#include #include #define stack_size 5 void push(int item,int *top,int s[]) { if(*top==stack_size-1) { printf("Stack overflows"); return; } s[++(*top)]=item; } int pop(int *top,int s[]) { int item; if(*top==-1) { return 0; } item=s[(*top)--]; return item; } void display(int top,int s[]) { int i; if(top==-1) { printf("stack is empty \n"); return; } printf("contents of the stack \n"); for(i=0;i<=top;i++) { printf("%d \n",s[i]); } } void main() { int top,s[10],item,choice; top=-1; for(;;) { clrscr(); printf("1:Push\n 2:Pop\n3:Display 4:Exit\n"); printf("enter yours choice \n"); scanf("%d",&choice); switch(choice) { case 1: printf("enter the item to be inserted \n"); scanf("%d",&item); push(item,&top,s); break; case 2: item=pop(&top,s); if(item==0) printf("stack is empty \n"); else printf("the deleted item =%d \n",item); break; case 3: display(top,s); break; default: exit(0); } } }