From 7c9c24bdd79002fc5d38ff76eb775a4b9deea809 Mon Sep 17 00:00:00 2001 From: kshitij Date: Thu, 1 Oct 2020 13:56:35 +0530 Subject: [PATCH] Queue Program Added --- kshitij_9896QUEUELIS.CPP | 119 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 kshitij_9896QUEUELIS.CPP diff --git a/kshitij_9896QUEUELIS.CPP b/kshitij_9896QUEUELIS.CPP new file mode 100644 index 0000000..7bcd443 --- /dev/null +++ b/kshitij_9896QUEUELIS.CPP @@ -0,0 +1,119 @@ +/*Program to implement queue using linkedlist +author-Kshitij bansod*/ +#include +#include +#include + +class qlink +{ + struct node + { + int info; + node *next; + }*front,*rear,*ptr,*i,*x; + + public: + qlink() + { + front=rear=NULL; + } + void insertion(); + void deletion(); + void display(); + + }; + + void qlink::insertion() + { + int no; + cout<<"\n Enter number"; + cin>>no; + ptr=new node; + ptr->info=no; + ptr->next=NULL; + + if(front==NULL) + { + front=ptr; + rear=ptr; + } + else + { + rear->next=ptr; + rear=ptr; + } + cout<<"\n Node inserted"; + } + + void qlink::deletion() + { + if(front==NULL) + { + cout<<"\n Queue is empty"; + } + else + { + x=front; + cout<<"\n"<info<<"is Deleted from Queue"; + front=front->next; + delete x; + display(); + } + } + + void qlink::display() + { + if(front==NULL) + { + cout<<"\n Queue is empty"; + } + else + { + cout<<"\n Queue is"; + for(i=front;i!=NULL;i=i->next) + { + cout<<" "<info; + } + } + + } + + void main() + { + int ch; + qlink obj; + clrscr(); + while(ch!=0) + { + + cout<<"\n**Queue Operations**"; + cout<<"\n 1.Insertion"; + cout<<"\n 2.Deletion"; + cout<<"\n 3.Display"; + cout<<"\n 0.Exit"; + + cout<<"\n Enter your choice"; + cin>>ch; + + switch(ch) + { + case 1: + obj.insertion(); + break; + case 2: + obj.deletion(); + break; + case 3: + obj.display(); + break; + case 0: + exit(0); + break; + + default: + cout<<"\n Wrong choice"; + } + } + getch(); + } +