0% found this document useful (0 votes)
38 views2 pages

Implementation of Queue Using Linked List

Uploaded by

Vivek Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Implementation of Queue Using Linked List

Uploaded by

Vivek Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Push and Pop Operations in a Queue with the Help of Linked List #include<iostream.h> #include<stdlib.h> #include<conio.

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;

} } if(a==4) break; getch(); } }

You might also like