#include
#include
#define MAX 5void Push();
void Pop();
void Display();
int stack[MAX],topstk=-1;
void main()
{ int choice;
clrscr();
while(1)
{
printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit"); printf("\n\nEnter ur choice:->");
scanf("%d",&choice);
switch (choice)
{
case 1: Push(); break;
case 2: Pop(); break;
case 3: Display(); break;
case 4: exit(0);
}
}
Display();
return;
}
void Push()
{
int item;
if (topstk==MAX)
printf("\n\nStack is Full");
else { topstk++; printf("\n\n enter the detail:->");
scanf("%d",&item);
stack[topstk]=item;
}
Display();
return;
}
void Pop()
{
int item;
if (topstk==-1)
printf("\nStack is Empty");
else { item=stack[topstk];
topstk--;
printf("\n\nthe deleted detail is %d",item);
}
Display();
return;
}
void Display()
{
int i;
if (topstk==-1)
printf("\nStack is Empty");
else { printf("\n Stack elements are:Front<--");
for(i=topstk;i>=0;i--)
printf("%d<--",stack[i]);
printf("Rear");
}
getch();
return;
}
No comments:
Post a Comment