#include<stdio.h>
#include<stdlib.h>
#define maxsize 50
void push();
int pop();
void display();
int stack[maxsize];
int top=-1;
main()
{
char choice;
printf("*****INSTRUCTIONS*****\nE - Enter\nX - Delete\nD - Display\nQ - Quit\n");
while(1)
{
printf("\nEnter choice: ");
scanf("%s",&choice);
switch(choice)
{
case 'E' :
push();
break;
case 'X' :
pop();
break;
case 'D' :
display();
break;
case 'Q' :
exit(1);
break;
}
}
}
void push()
{
int x;
printf("Enter element:");
scanf("%d",&x);
if(top == maxsize - 1)
{
printf("stack is full");
}
else
{
top++;
stack[top]=x;
}
}
int pop()
{
int x;
if(top==-1)
{
printf("stack is empty");
}
else
{
x=stack[top];
top--;
printf("The deleted element is %d\n",x);
}
}
void display()
{
int i;
printf("Elements in the stack are:");
for(i=0; i<=top; i++)
{
printf("%d\t",stack[i]);
}
}
Note: Need to be arranged in compiler after copied
OutPut:
*****INSTRUCTIONS*****
E - Enter
X - Delete
D - Display
Q - Quit
Enter choice: E
Enter element:1
Enter choice: E
Enter element:4
Enter choice: E
Enter element:2
Enter choice: X
The deleted element is 2
Enter choice: E
Enter element:3
Enter choice: D
Elements in the stack are:1 4 3
Enter choice: Q