Menu driven program by linked list implementation of queue
Tuesday, March 10, 2020//menu driven program by linked list implementation of queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int info;
node *next;
}*front,*rear,*np,*ptr,*temp;
void insert_Q(int INF)
{ ptr=new node;
ptr->info=INF;
ptr->next=NULL;
if(ptr==NULL)
exit(1);
if(front==NULL)
front=rear=ptr;
else
{ rear->next=ptr;
rear=ptr;
}
}
void delete_Q()
{ if(front==NULL)
cout<<"\n Underflow";
else
{ temp=front;
front=front->next;
}
delete temp;
}
void display(node *np)
{ clrscr();
cout<<"\t\t";
while(np!=NULL)
{ cout<<np->info<<"-->";
np=np->next;
}
cout<<"NULL";
}
void main()
{ clrscr();
front=rear=NULL;
int p,inf;
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT\n";
cout<<"\n Enter your choice:";
cin>>p;
if(p==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(p==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>inf;
insert_Q(inf);
goto l;
}
else if(p==2)
{ delete_Q();
goto l;
}
else
{ display(front);
goto l;
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int info;
node *next;
}*front,*rear,*np,*ptr,*temp;
void insert_Q(int INF)
{ ptr=new node;
ptr->info=INF;
ptr->next=NULL;
if(ptr==NULL)
exit(1);
if(front==NULL)
front=rear=ptr;
else
{ rear->next=ptr;
rear=ptr;
}
}
void delete_Q()
{ if(front==NULL)
cout<<"\n Underflow";
else
{ temp=front;
front=front->next;
}
delete temp;
}
void display(node *np)
{ clrscr();
cout<<"\t\t";
while(np!=NULL)
{ cout<<np->info<<"-->";
np=np->next;
}
cout<<"NULL";
}
void main()
{ clrscr();
front=rear=NULL;
int p,inf;
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT\n";
cout<<"\n Enter your choice:";
cin>>p;
if(p==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(p==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>inf;
insert_Q(inf);
goto l;
}
else if(p==2)
{ delete_Q();
goto l;
}
else
{ display(front);
goto l;
}
getch();
}
0 Comments