Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. const int s = 100000;
  5. int d [s], f, l;
  6. int r_i (int i){
  7. return ((i%s +s)%s);
  8. }
  9. void push_front (int x){
  10. d [r_i(f)] = x;
  11. --f;
  12. cout << "ok" << endl;
  13. }
  14. void push_back (int x){
  15. d [r_i(l)] = x;
  16. ++l;
  17. cout << "ok" << endl;
  18. }
  19. int pop_front (int x){
  20. return (r_i(f));
  21. f++;
  22. }
  23. int pop_back (){
  24. return (r_i(l));
  25. --l;
  26. }
  27. int back (){
  28. return (d[r_i(l-1)]);
  29. }
  30. int front (){
  31. return (d[r_i(f+1)]);
  32. }
  33. int size (){
  34. return (l-f-1);
  35. }
  36. bool empty (){
  37. return (size() == 0);
  38. }
  39. void clear (){
  40. while (!empty){
  41. pop_back;
  42. }
  43. cout <<"ok"<< endl;
  44. }
  45. void exit(){
  46. cout <<"bye"<<endl;
  47. }
  48. int main(){
  49. string b;
  50. int a, c, d, e, f;
  51. while true{
  52. cin >> n;
  53. switch n:
  54. case ("push_front")
  55. {
  56. cin >> a;
  57. push_front (a)
  58. }
  59. case ("push_back")
  60. {
  61. cin >> c;
  62. push_back (c)
  63. }
  64. case ("push_front")
  65. {
  66. cin >> d;
  67. push_front (d)
  68. }
  69. case ("pop_front")
  70. {
  71. pop_front ()
  72. }
  73. case ("pop_back")
  74. {
  75. pop_back ()
  76. }
  77. case ("back")
  78. {
  79. cout<<back;
  80. }
  81. case ("front")
  82. {
  83. cout<<front;
  84. }
  85. case ("exit")
  86. {
  87. exit ()
  88.  
  89. }
  90. case ("clear")
  91. {
  92. cin >> a;
  93. push_front (a)
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement