Advertisement
wurdalak007

Untitled

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