Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- stack<int>st1,st2;
- void show(stack <int> st1)
- {
- while(!st1.empty())
- {
- cout<<st1.top()<<" ";
- st1.pop();
- }
- cout<<endl;
- }
- void enqueue(int element)
- {
- while (!st1.empty())
- {
- st2.push(st1.top());
- st1.pop();
- }
- st1.push(element);
- while (!st2.empty())
- {
- st1.push(st2.top());
- st2.pop();
- }
- show(st1);
- }
- void dequeue(stack <int> st)
- {
- st.pop();
- //show(st);
- }
- void del(stack <int> st)
- {
- if(!st.empty())
- {
- st.pop();
- cout<<"SIZE:"<<" "<<"0"<<" "<<"ITEMS:"<<" "<<"NULL";
- }
- else
- {
- cout<<"SIZE:"<<" "<<"0"<<" "<<"ITEMS:"<<" "<<"NULL";
- }
- }
- int main()
- {
- int length;
- cin>>length;
- int t;
- cin>>t;
- while(t--)
- {
- int choice;
- cin>>choice;
- if(choice==1)
- {
- int element;
- cin>>element;
- if(st1.size()==length)
- {
- cout<<"Size:"<<st1.size()<<" elements: Overflow!"<<endl;
- }
- else
- {
- cout<<"Size:"<<st1.size()+1<<" elements: ";
- enqueue(element);
- }
- }
- else if(choice==2)
- {
- if(st1.size()>0)
- {
- cout<<"Size: "<<st1.size()-1<<" elements: ";
- dequeue(st1);
- if(st1.empty())
- {
- cout<<"NULL"<<endl;
- }
- show(st1);
- }
- else
- {
- del(st1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment