PROGRAM
#include<stdio.h>#include<conio.h>
#define MAX 5
int top=-1;
int a[MAX];
void display()
{
int i;
if(top!=-1)
{
printf("\nElements of stack are:: ");
for(i=0;a[i]!=0;i++)
printf("%d\t",a[i]);
}
else
printf("\n\nEMPTY STACK");
}
int push()
{
int num,i;
//for(i=0;i<20;i++)
//a[i]='\0';
if(top==(MAX-1))
printf("\n\t! OVERFLOW\n");
else
{
printf("\nEnter the number to push in to the stack");
scanf("%d",&num);
for(i=0;i<MAX;i++)
{
if(a[i]==num)
{
printf("\nNumber already exist");
return 0;
}
}
a[++top]=num;
}
display();
return 1;
}
void pop()
{
if(top==-1)
printf("\n\t! UNDERFLOW");
else
{
printf("\nElement poped::\t");
printf("%d",a[top]);
a[top]=0;
top--;
}
display();
}
void main()
{
int opt;
char ch;
clrscr();
while (1)
{
printf("\nEnter the option\n\t1.PUSH\n\t2.POP\n\t3.EXIT");
scanf("%d",&opt);
switch(opt)
{
case 1:push();break;
case 2:pop();break;
case 3:exit(0);
default:printf("\n\t\tINVALID CHOICE");break;
}
//printf("\npress y to continue");
//ch=getche();
}//while(ch=='Y'||ch=='y');
}