Advertisement
Trawka011

Untitled

Nov 22nd, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #define sizeh 1000
  3.  
  4. using namespace std;
  5.  
  6. int* deque;
  7. int dh = 500, dt = 500, sum = 0;;
  8.  
  9. void push_front( int x)
  10. {
  11.     if (dh < 1) dh += sizeh;
  12.     deque[(--dh) % sizeh] = x;
  13.     sum++;
  14. }
  15.  
  16. void push_back( int x)
  17. {
  18.     deque[(dt++) % sizeh] = x;
  19.     sum++;
  20. }
  21.  
  22. int pop_front()
  23. {
  24.     sum--;
  25.     return deque[(dh++) % sizeh];
  26. }
  27.  
  28. int pop_back()
  29. {
  30.     sum--;
  31.     if (dt < 1) dt += sizeh;
  32.     return deque[(--dt) % sizeh];
  33. }
  34.  
  35. void del_deque() {
  36.     dt = 500;
  37.     dh = 500;
  38.     sum = 0;
  39. }
  40.  
  41. int main() {
  42.     int a = 0,  b = 0; 
  43.     deque = new int[sizeh];
  44.     while(cin >> a){
  45.         if (a == 1) {
  46.             cin >> b;
  47.             push_front(b);
  48.         }
  49.         else if (a == 2) {
  50.             cin >> b;
  51.             push_back(b);
  52.         }
  53.         else if (a == 3) {
  54.             cout << pop_front();
  55.         }
  56.         else if (a == 4) {
  57.             cout << pop_back();
  58.         }
  59.         else if (a == 5) {
  60.            
  61.         }
  62.         else if (a == 6) {
  63.            
  64.         }
  65.         else if (a == 7) {
  66.             cout << sum;
  67.         }
  68.         else if (a == 8) {
  69.             del_deque();
  70.         }
  71.         else if (a == 9) {
  72.             return 0;
  73.         }
  74.     }
  75.     delete[] deque;
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement