Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int A[5], top = -1;
- void push(int item)
- {
- if(top == 4)
- {
- cout<<"Stack is full"<<endl<<endl;
- }
- else
- {
- top = top + 1;
- A[top] = item;
- }
- cout<<"Added number : "<< item << " position : "<< top <<endl;
- }
- void pop()
- {
- int item;
- if (top == - 1)
- {
- cout<<"Stack is empty"<<endl;
- }
- else
- {
- item = A [top];
- cout <<"Deleted number is : " << item << " position : "<< top<<endl;
- top = top - 1;
- }
- }
- void print()
- {
- if(top == -1)
- {
- cout<<"Stack is empty !"<<endl;
- }
- else
- {
- cout<<"Stack : "<<endl;
- //for(int i=4; i>=0;i--)
- for(int i=top; i > -1; i--)
- {
- cout<<A[i]<< "("<<i<<")"<<endl;
- }
- }
- cout<<endl;
- }
- int main()
- {
- cout<<"Push operation"<<endl;
- push(100); print();
- push(99); print();
- push(88); print();
- push(77); print();
- push(66);print();
- cout<<"Pop operation"<<endl;
- pop(); print();
- pop(); print();
- pop(); print();
- pop(); print();
- pop(); print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement