Linked list implementation of Queue

sindhias 1,864 views 7 slides Sep 08, 2020
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Linked list implementation of Queue


Slide Content

LINKED LIST
IMPLEMENTATION OF
QUEUE
MODULE 3
1

IMPLEMENTING QUEUES USING
LINKED LISTS
•Allocatememoryforeachnewelementdynamically
•Linkthequeueelementstogether
•Usetwopointers,FrontandRear,tomarkthefrontand
rearofthequeue
Dr. SINDHIA LINGASWAMY, VIT
2

•Inalinkedqueue,everyelementhastwoparts,onethatstoresthe
dataandanotherthatstorestheaddressofthenextelement.
•TheSTARTpointerofthelinkedlistisusedasFRONT.
•Here,wewillalsouseanotherpointercalledREAR,whichwillstore
theaddressofthelastelementinthequeue.
•Allinsertionswillbedoneattherearendandallthedeletionswill
bedoneatthefrontend.
•IfFRONT=REAR=NULL,thenitindicatesthatthequeueisempty.
Dr. SINDHIA LINGASWAMY, VIT
3

ENQUEUING (EMPTY
QUEUE)
We need to make Frontpoint to the new node
also
New Node
newNode
Dr. SINDHIA LINGASWAMY, VIT
4

FUNCTION ENQUEUE
Dr. SINDHIA LINGASWAMY, VIT
5

DEQUEUEING (THE QUEUE
CONTAINS ONLY ONE ELEMENT)
•We need to reset Rearto NULL also
Nod
e
qFront
qRear
After dequeue:
qFront = NULL
qRear = NULL
Dr. SINDHIA LINGASWAMY, VIT
6

Function Dequeue
Dr. SINDHIA LINGASWAMY, VIT
7