Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7.  
  8. void print_queue(queue<int> q)
  9. {
  10. vector<int> v;
  11. while (!q.empty())
  12. {
  13. v.push_back(q.front());
  14. q.pop();
  15. }
  16. for(int i = v.size()-1;i>=0;i--)
  17. {
  18. cout<<v[i]<<" ";
  19. }
  20. cout << endl;
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26. queue<int> q;
  27.  
  28. q.push(100);
  29. q.push(0);
  30. print_queue(q);
  31.  
  32. int a = 0;
  33. int b = 0;
  34.  
  35. while(1)
  36. {
  37. a = q.front();
  38. q.pop();
  39. print_queue(q);
  40. if(a == 0) break;
  41. q.push(a);
  42. print_queue(q);
  43. q.push(a);
  44. print_queue(q);
  45. q.push(1);
  46. print_queue(q);
  47. int x = q.front();q.pop();
  48. int y = q.front();q.pop();
  49. q.push(x+y);
  50. print_queue(q);
  51. x = q.front();q.pop();
  52. y = q.front();q.pop();
  53. q.push(x-y);
  54. print_queue(q);
  55. b = q.front();q.pop();
  56. q.push(b);
  57. print_queue(q);
  58. cout<<"----------------------------------\n";
  59.  
  60. }
  61. cout << q.front();
  62.  
  63.  
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement