Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int N;
- void push(int s[],int &top,int item)
- {
- if(top>=N)
- cout<<"Full"<<endl;
- else
- {
- s[top]=item;
- top++;
- }
- }
- int pop(int s[],int &top)
- {
- if(top==0)
- cout<<"Empty"<<endl;
- else
- {
- --top;
- return s[top];
- }
- }
- int main()
- {
- cin>>N;
- int t,i,ar[N],top=0,j;
- 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;
- push(ar,top,b);
- }
- else
- pop(ar,top);
- cout<<"size= "<<top;
- cout<<" items= ";
- if(top==0)
- cout<<"NULL"<<endl;
- else
- {
- for(j=0; j<top; j++)
- {
- cout<<ar[j]<<" ";
- }
- cout<<"\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement