Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define max 5
- int stack[max+1]={0,0,0,0,0,0};
- int top=0;
- void push()
- {
- if(top==max) printf("\nStack Overflow\n");
- else-{
- int num;
- printf("Enter the number: ");
- scanf("%d",&num);
- top++;
- stack[top]=num;
- }
- }
- void pop()
- {
- if(top==0) printf("\nUnderflow\n");
- else
- {
- int item;
- item=stack[top];
- stack[top]=0;
- top--;
- printf("The deleted item is: %d\n",item);
- }
- }
- void display()
- {
- int i;
- printf("\nThe stack is:\n");
- for(i=max;i>0;i--)
- {
- printf("%d\n",stack[i]);
- }
- printf("\n");
- }
- int main()
- {
- int x;
- while(1)
- {
- printf("Press 1 to insert element\n");
- printf("Press 2 to remove element\n");
- scanf("%d",&x);
- if(x==1) push();
- else if(x==2) pop();
- display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement