Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define max 10
- struct stack
- {
- int top;
- int items[max];
- }s;
- void push();
- void pop();
- void display();
- void main()
- {
- s.top=-1;
- int choice;
- top1:
- printf("1.push\n2.pop\n3.display\n4.exit");
- scanf("%d",&choice);
- switch(choice){
- case 1:
- push();
- break;
- case 2:
- pop();
- break;
- case 3:
- display();
- break;
- case 4:
- exit(0);
- default:
- printf("Enter number in range: ");
- }
- goto top1;
- }
- void push(){
- if((s.top)==max-1)
- {
- printf("Stack overflow");
- }
- else{
- int d;
- s.top=s.top+1;
- printf("Enter the element: ");
- scanf("%d",&s.items[s.top]);
- }
- }
- void pop(){
- if(s.top==-1)
- {
- printf("Stack underflow");
- }
- s.top=s.top-1;
- }
- void display(){
- printf("The element are");
- printf("\n [");
- int i;
- for(i=0;i<=s.top;i++)
- {
- printf(" %d ",s.items[i]);
- }
- printf("]");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement