Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int a[10],choice,i,n,top=-1,x;
- void push()
- {
- if(top>=n-1)
- {
- printf("Stack is overflow\n");
- }
- else
- {
- printf("Enter the data to add\n");
- scanf("%d",&x);
- top++;
- a[top]=x;
- }
- }
- void pop()
- {
- if(top==-1)
- {
- printf("the stack is underflow\n");
- }
- else
- {
- printf("The poped element is:%d",a[top]);
- top--;
- }
- }
- void display()
- {
- if(top>=0)
- {
- printf("Elements are there\n");
- for(i=top; i>=0; i--)
- {
- printf("%d\n",a[i]);
- }
- printf("Press the next choice\n",choice);
- }
- else
- {
- printf("There is no element\n");
- }
- }
- int main()
- { printf("Enter the stack size:");
- scanf("%d",&n);
- do
- {
- printf("Enter choice:");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- {
- push();
- break;
- }
- case 2:
- {
- pop();
- break;
- }
- case 3:
- {
- display();
- break;
- }
- case 4:
- {
- printf("Exit");
- break;
- }
- default:
- {
- printf("Invalid");
- }
- }
- }
- while(choice!=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment