Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- using namespace std;
- int N;
- void showstack(stack <int> s)
- {
- while (!s.empty())
- {
- cout << s.top()<<" ";
- s.pop();
- }
- cout << '\n';
- }
- int main()
- {
- cin>>N;
- stack <int> s;
- int t,i;
- cin>>t;
- for(i=0; i<t; i++)
- {
- cout<<"Enter 1 to push and 2 to pop"<<endl;
- int a;
- cin>>a;
- if(a==1)
- {
- cout<<"Enter number"<<endl;
- int b;
- cin>>b;
- s.push(b);
- }
- else
- s.pop();
- cout << "size= " << s.size();
- cout<<" items= ";
- if(!s.empty())
- showstack(s);
- else
- cout<<"NULL"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement