/**********STACK IMPLEMENTATION USING ARRAY**********/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5
int top=-1;
int st[MAX];
void main()
{
int x,ch;
void push (int);
int pop();
void show();
clrscr();
while(1)
{
printf("\n1.Push");
printf("\n2.Pop");
printf("\n3.Display");
printf("\nExit");
printf("\nEnter your choice::");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(top>=MAX-1)
printf ("\nStack is full");
else
{
printf("\Enter number ::");
scanf("%d",&x);
push(x);
}
break;
case 2:
if(top==-1)
printf("\nStack is empty");
else
printf("\nThe poped item=%d",pop());
break;
case 3:
show();
break;
case 4:
exit(0);
}
}
getch();
}
void push(int x)
{
top++;
st[top]=x;
}
int pop()
{
int x;
x=st[top--];
return x;
}
void show()
{
int i;
if(top>=0)
{
for(i=top;i>=0;i--)
printf("%4d",st[i]);
}
else
printf("\nStack is empty");
}