Implementation of Queue Using Linked List
Implementation of Queue Using Linked List
h> struct node { int data; struct node *link; }; void main() { int a; struct node *front=NULL,*rear=NULL,*temp; while(1) { clrscr(); cout<<"What do you want to do?\n1. Enqueue\n2. Dequeue\n"; cout<<"3. Display\n4. Exit\n\n"; cin>>a; clrscr(); if(a==1) { temp=(struct node *)malloc(sizeof(struct node)); cout<<"Element to be added :"; cin>>temp->data; if(front==NULL) front=temp; if(rear!=NULL) rear->link=temp; rear=temp; cout<<"Element added!"; } if(a==2) { if(front==NULL) cout<<"Queue Underflow!"; else { cout<<"Element deleted :"<<front->data; if(front==rear) front=rear=NULL; else front=front->link; } } if(a==3) { cout<<"Elements:"; if(front!=NULL) { temp=front; while(temp!=rear) { cout<<"\n"<<temp->data; temp=temp->link; } cout<<"\n"<<temp->data;