int data[9],rear=-1;
void push(int val)
{
if(rear==8)
{
printf("\n\n\t\tStack is Full");
return;
}
rear++;
data[rear]=val;
}
void pop()
{
if(rear==-1)
{
printf("\n\n\t\tStack is Empty");
return;
}
rear--;
}
void disp()
{
int a;
if(rear==-1)
{
printf("\n\n\t\tStack is Empty");
return;
}
for(a=rear;a>=0;a--)
printf("\n\t\t\t%d",data[a]);
}
void menu()
{
gotoxy(34,1); printf("MENU\n");
printf("\t-------------------------------------------------");
gotoxy(29,3); printf("1. Display the LIST");
gotoxy(29,4); printf("2. Inserting an element");
gotoxy(29,5); printf("3. Deleting an element");
gotoxy(29,6); printf("4. EXIT");
printf("\n\t-------------------------------------------------");
}
main()
{
int a;
char ch;
while(ch!='n'&&ch!='N')
{
clrscr();
menu();
printf("\n\n\t\tEnter your choice-> "); fflush(stdin);
ch=getche();
if(ch=='1')
disp();
else
if(ch=='2')
{
printf("\nenter the element-> \n");
scanf("%d",&a);
push(a);
}
else
if(ch=='3')
pop();
else
if(ch=='4')
exit(0);
getch();
}
}
0 comments:
Post a Comment