Advertisement
maycod23

Untitled

May 29th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. class MyStack {
  6. public:
  7. queue<int> q;
  8. int tempsize;
  9. MyStack() {
  10.  
  11. }
  12.  
  13. void push(int x) {
  14. tempsize = q.size();
  15. q.push(x);
  16. while (tempsize > 0)
  17. {
  18. q.push(q.front());
  19. q.pop();
  20. tempsize--;
  21. }
  22. }
  23.  
  24. int pop() {
  25. int temp = q.front();
  26. q.pop();
  27. return temp;
  28. }
  29.  
  30. int top() {
  31. return q.front();
  32. }
  33.  
  34. bool empty() {
  35. if (q.empty()) return true;
  36. return false;
  37. }
  38. };
  39.  
  40.  
  41. int main()
  42. {
  43. //declaration- by default empty stack
  44. // stack<int> stk;
  45. // int n; cin >> n;
  46. // while (n--)
  47. // {
  48. // int x; cin >> x;
  49. // stk.push(x);
  50. // }
  51. // while (!stk.empty())
  52. // {
  53. // cout << stk.top() << endl;
  54. // stk.pop();
  55. // }
  56.  
  57.  
  58.  
  59. // queue<int> q;
  60. // int n; cin >> n;
  61. // while (n--)
  62. // {
  63. // int x; cin >> x;
  64. // q.push(x);
  65. // }
  66.  
  67. // while (q.size() > 0)
  68. // {
  69. // cout << q.front() << " ";
  70. // q.pop();
  71. // }
  72.  
  73.  
  74.  
  75. MyStack stk;
  76. int n; cin >> n;
  77. while (n--)
  78. {
  79. int x; cin >> x;
  80. stk.push(x);
  81. }
  82. while (!stk.empty())
  83. {
  84. cout << stk.top() << endl;
  85. stk.pop();
  86. }
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement