// Implementation of Stack using Array
#include<stdio.h>
#include<conio.h>
#define max 5
int stack[max];
int top=-1;
// function for push the element into stack
void push()
{
int element ;
if(top==max-1)
printf("Overflow");
else
{
printf("Enter a number ");
scanf("%d",&element);
top=top+1;
stack[top]=element;
}
}
// function for pop the element from the stack
void pop()
{
int element;
if(top==-1)
printf("Underflow condition");
else
{
element=stack[top];
printf("pop element is %d",element);
top=top-1;
}
}
// function for display the element of the stack
void display()
{
int element,i;
if(top==-1)
printf("Underflow condition");
else
{
for(i=top;i>=0;i--)
{
printf("%d ",stack[i]);
}
}
}
//Driver function
void main()
{
int ch;
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
while(1)
{
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default:
printf("Worng key");
}
}
}