Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class MyStack {
- public:
- queue<int> q;
- int tempsize;
- MyStack() {
- }
- void push(int x) {
- tempsize = q.size();
- q.push(x);
- while (tempsize > 0)
- {
- q.push(q.front());
- q.pop();
- tempsize--;
- }
- }
- int pop() {
- int temp = q.front();
- q.pop();
- return temp;
- }
- int top() {
- return q.front();
- }
- bool empty() {
- if (q.empty()) return true;
- return false;
- }
- };
- int main()
- {
- //declaration- by default empty stack
- // stack<int> stk;
- // int n; cin >> n;
- // while (n--)
- // {
- // int x; cin >> x;
- // stk.push(x);
- // }
- // while (!stk.empty())
- // {
- // cout << stk.top() << endl;
- // stk.pop();
- // }
- // queue<int> q;
- // int n; cin >> n;
- // while (n--)
- // {
- // int x; cin >> x;
- // q.push(x);
- // }
- // while (q.size() > 0)
- // {
- // cout << q.front() << " ";
- // q.pop();
- // }
- MyStack stk;
- int n; cin >> n;
- while (n--)
- {
- int x; cin >> x;
- stk.push(x);
- }
- while (!stk.empty())
- {
- cout << stk.top() << endl;
- stk.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement