Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 5
- int push(int[],int);
- int pop(int[],int);
- void display(int[],int);
- int main()
- {
- system("clear");
- int stack[MAX],top,item,ch;
- top=-1;
- while(1)
- {
- printf("\n0: Quit");
- printf("\n1: Push");
- printf("\n2: Pop");
- printf("\n3: Display");
- printf("\nEnter choice:");
- scanf("%d",&ch);
- switch(ch)
- {
- case 0: return 0;
- case 1: top=push(stack,top);
- break;
- case 2: top=pop(stack,top);
- break;
- case 3: display(stack,top);
- break;
- default:printf("\nInvalid choice");
- }
- }
- }
- int push(int stack[],int top)
- {
- int item;
- if(top==MAX-1)
- {
- printf("\nOverflow");
- return 0;
- }
- printf("\nEnter item: ");
- scanf("%d",&item);
- top++;
- stack[top]=item;
- return top;
- }
- int pop(int stack[],int top)
- {
- int item;
- if(top==-1)
- {
- printf("\nUnderflow");
- return 0;
- }
- item=stack[top];
- top--;
- printf("\nItem poped= %d",item);
- return top;
- }
- void display(int stack[],int top)
- {
- int i;
- printf("\nStack elements are: ");
- for(i=0;i<=top;i++)
- printf("%d ",stack[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement