44)Write a menu driven program using C for Dynamic implementation of stack. -Push -Pop -Display -Exit


#include<stdio.h>
#include<conio.h>
struct list
{
int data;
struct list *next;
struct list *prev;
}*start;
void create(int);
void disp();
void ser(int);
void main()
{
int i,n,m,ch;
start=NULL;
clrscr();
do
{
printf(“\n\nMENU\n\n”);
printf(“\n\n1.CREATE\n\n”);
printf(“\n\n2.DISP\n\n”);
printf(“\n\n3.SEARCH\n”);
printf(“\n\n4.EXIT\n\n”);
printf(“\n\nENTER UR CHOICE\n\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“\n\nHOW MANY NODES”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“\n\nENTER THE DATA\n\n”);
scanf(“%d”,&m);
create(m);
}
break;
case 2:
disp();
break;
case 4:
exit(0);
case 3:
printf(“\n\nENTER THE ELEMENT FOR SEARCH”);
scanf(“%d”,&m);
ser(m);
break;
}
}
while(ch!=4);
getch();
}

void create(int m)
{
struct list *q,*tmp;
tmp=(struct list*)malloc(sizeof(struct list));
tmp->data=m;
tmp->next=NULL;
if(start==NULL)
{
tmp->prev=start;
start->next=tmp;
start=tmp;
}
else
{
q=start;
while(q->next!=NULL)
{
q=q->next;
}
q->next=tmp;
tmp->prev=q;
}
}
void disp()
{
struct list *q;
if(start==NULL)
{
printf(“\n\nLIST IS ENPTY\n\n”);
}
else
{
q=start;
while(q!=NULL)
{
printf(“%d->”,q->data);
q=q->next;
}
printf(“NULL”);
}
}
void ser(int m)
{
struct list *q;
q=start;
while (q!=NULL)
{
if(q->data==m)
{
printf(“\nELEMENT IS FOUND”);
break;
}
q=q->next;
}
if(q==NULL)
{
printf(“\nELEMENT IS NOT FOUND”);
}
}

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