Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define stacksize 10
- struct stack
- {
- int num[stacksize];
- int top;
- int count;
- }s;
- void push(void);
- void pop(void);
- void display(void);
- void main()
- {
- s.count=0;
- s.top=-1;
- int choice;
- label: printf("enter a choice to perform the following operations on stack\n 1)PUSH\n 2)POP\n 3)DISPLAY\n");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- push();
- break;
- case 2:
- pop();
- break;
- case 3:
- display();
- break;
- default:
- printf("wrong choice entered\n");
- break;
- }
- goto label;
- }
- void push()
- {
- int x;
- if(s.top==stacksize)
- printf("the stack is full\n");
- else
- s.top++;
- printf("enter an element\n");
- scanf("%d",&x);
- s.num[s.top]=x;
- }
- void pop()
- {
- int b;
- if(s.top==-1)
- printf("the stack is empty\n");
- else
- b=s.num[s.top];
- s.top--;
- s.count--;
- printf("the elment %d is popped from the stack\n",b);
- }
- void display()
- {
- int i;
- if(s.top==-1)
- printf("the stack is empty\n");
- else
- for(i=s.top;i>0;i--)
- printf("the elements are:\n %d\n",s.num[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment