14)Write a menu drive program using C for static implementation of statck.the menu include. -Push -Pop -Display


#include<stdio.h>
#include<conio.h>
#define MAX 10
int top=-1;
int stk[MAX];
void push();
void pop();
void disp();
void main()
{
int ch;
clrscr();
do
{
printf(“\n\nMenu \n\n”);
printf(“\n1.Push\n”);
printf(“\n2.Pop\n”);
printf(“\n3.Display \n”);
printf(“\n4.Exit \n”);
printf(“\n\nEnter the Choice \n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
disp();
break;
case 4:
exit(0);
}
}
while(ch!=4);
getch();
}
void push()
{
int n;
printf(“\n\nEnter the Element for Insert \n”);
scanf(“%d”,&n);
if(top==MAX-1)
{
printf(“\nStack Is Full\n”);
}
else
{
top++;
stk[top]=n;
}
}
void pop()
{
if(top==-1)
{
printf(“\n Stack Is Empty \n”);
}
else
{
printf(“\nPop Element Is %d”,stk[top]);
top–;
}
}

void disp()
{
int i;
if(top!=-1)
{
printf(“\n\nStack Elements Are \t”);
for(i=top;i>=0;i–)
{
printf(“->%d”,stk[i]);
}
}
else
{
printf(“\n\nStack is Empty \n\n”);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s