#include<stdio.h>
#define MAX 10
int stack[MAX],top=-1;
void push(int);
void pop();
void display(void);
int main()
{
int num,choice;
do
{
printf("\n 1.PUSH\n 2.POP\n 3.DISPLAY\n 4.EXIT");
printf("\n Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf(" Enter a value to be pushed:");
scanf("%d",&num);
push(num);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
printf("\n EXIT POINT ");
break;
default:
printf ("\n Invalid Choice");
}
}
while(choice!=4);
return 0;
}
void push(int n)
{
if(top>=MAX-1)
{
printf("\nSTACK is over flow");
}
else
{
top++;
stack[top]=n;
}
}
void pop()
{
if(top<=-1)
{
printf("\n Stack is under flow");
}
else
{
printf("\n The popped elements is %d",stack[top]);
top--;
}
}
void display()
{
int i;
if(top>=0)
{
printf("\n The elements in STACK \n");
for(i=top; i>=0; i--)
printf("%d\t",stack[i]);
}
else
{
printf("\n The STACK is empty");
}
}