Aim: - To implement
Stack using array.
#include<stdio.h>
#include<conio.h>
#include<process.h>
void
push(); void pop(); void display();
int
top; int a[5];
void main()
{
int choice; char ch; top=-1; clrscr(); do
{
printf("\n\t 1. PUSH");
printf("\n\t 2. POP");
printf("\n\t 3. DISPLAY");
printf("\n\t 4. EXIT");
printf("\nEnter your choice"); scanf("%d",&choice); switch(choice)
{
case 1: push(); break;
case 2: pop(); break;
case 3: display();
break; case 4:
exit(0); default:
printf("\nBAD
CHOICE");
}
printf("\ndo you
want to continue y/n"); ch=getche();
}
while(ch=='y');
}
void push()
{
int item; if(top==4)
printf("STACK
IS FULL");
else
{
printf("Enter the item to be inserted"); scanf("%d",&item);
top=top+1; a[top]=item;
//top=tope;
}
}
void pop()
{
int item; if(top==-1)
printf("STACK
IS EMPTY");
else
{
item=a[top]; top=top-1;
printf("%d is deleted",item);
//top=tope;
}
void display()
{
int i; for(i=top;i>=0;i--)
printf("\n%d",a[i]);
}