Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define max 5
- using namespace std;
- int pop(int *top,int *data);
- int push(int *top,int *data);
- int stck[5];
- int main(){
- int top,option,reply,data;
- top=-1;
- while(1){
- cout<<"1.Push"<<endl;
- cout<<"2.Pop"<<endl;
- cout<<"3.Break"<<endl;
- cin>>option;
- switch (option){
- case 1:
- cout<<"Enter a value: ";
- cin>>data;
- reply=push(&top ,&data);
- if(reply==-1){
- cout<<"Overflow / stack if full"<<endl;
- }else{
- cout<<"Pushed value is "<<data<<endl;
- }
- break;
- case 2:
- cout<<"Enter a value: ";
- cin>>data;
- reply=pop(&top ,&data);
- if(reply==-1){
- cout<<"Underflow / stack if Empty"<<endl;
- }else{
- cout<<"Poped value is "<<data<<endl;
- }
- break;
- case 3:
- return 0;
- }
- }
- return 0;
- }
- int push(int *top,int *data){
- if(*top==-1)
- return (-1);
- else{
- *top=*top+1;
- stck[*top]=*data;
- return (1);
- }
- }
- int pop(int *top,int *data){
- if(*top==-1)
- return (-1);
- else{
- *data=stck[*top];
- *top=*top-1;
- return (1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement