Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define max 5
- int top,stack[max],i;
- void push ()
- {
- int value ;
- if(top==max-1) printf("overload \n");
- else
- {
- printf("Enter element to push");
- scanf("%d",&value);
- top=top+1;
- stack[top]=value;
- }
- }
- void pop()
- {
- if(top==-1) printf("No element \n");
- else
- {
- printf("deleted element %d \n",stack[top]);
- top=top-1;
- }
- }
- void desplay()
- {
- if(top==-1) printf("No element");
- else
- {
- printf("\n stack is \n");
- for(i=top; i>0; --i)
- printf("%d ",stack[i]);
- }
- }
- void main()
- {
- int op;
- while(1)
- {
- printf("\n stack menu \n");
- printf("1.push\n2.pop\n3.display\n4.exit\n");
- printf("Enter the chose: ");
- scanf("%d",&op);
- if(op==1)
- {
- push();
- }
- else if(op==2)
- {
- pop();
- }
- else if(op==3)
- {
- desplay();
- }
- else
- {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment