Advertisement
wurdalak007

Untitled

Sep 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. class Queque
  6. {
  7.  
  8. public:
  9.  
  10. void pushBack( int b ) {
  11.  
  12. if (size == 0) {
  13. initArray(256);
  14. }
  15.  
  16. if (count == size) {
  17. extendMem();
  18. head = 0;
  19. tail = size / 2;
  20. }
  21. array[ tail % size ] = b;
  22. tail++;
  23. count++;
  24.  
  25. }
  26.  
  27. int popFront() {
  28. if (count == 0) {
  29. return -1;
  30. }
  31. head++;
  32. count--;
  33. return array[head - 1];
  34. }
  35. void clear() {
  36. delete[] array;
  37. }
  38.  
  39. private :
  40. int count = 0;
  41. int size = 0;
  42. int head = 0;
  43. int tail = 0;
  44. int *array;
  45.  
  46.  
  47. void extendMem()
  48. {
  49. int i = 0;
  50.  
  51. size = size * 2;
  52. int *array1 = new int[size];
  53. for (int j = head; j < tail; j++) {
  54. array1[i] = array[ j % (size / 2) ];
  55. i++;
  56.  
  57. }
  58.  
  59. delete[] array;
  60. array = array1;
  61.  
  62. }
  63.  
  64. void initArray(int size) {
  65. array = new int[size];
  66. this->size = size;
  67. }
  68.  
  69. };
  70.  
  71.  
  72. int main() {
  73. int a = 0;
  74. int b = 0;
  75. int n = 0;
  76. bool flag = true;
  77. Queque Myclass;
  78.  
  79. std::cin >> n;
  80.  
  81.  
  82. for (int i = 1; i <= n; i++) {
  83. std::cin >> a >> b;
  84. if (a == 2) {
  85. if (b == Myclass.popFront() && (flag)) {
  86. flag = true;
  87. }
  88. else {
  89. flag = false;
  90. }
  91. }
  92. if (a == 3) {
  93. Myclass.pushBack(b);
  94. }
  95. }
  96.  
  97. if (flag) {
  98. std::cout << "YES";
  99. }
  100. else {
  101. std::cout << "NO";
  102. }
  103. Myclass.clear();
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement