Queue
Queue
Introduction
Operations on queue
Array representation of queues
Linked representation of queues
Types of queues
Circular queues
Deques
Priority queues
Application of queues
References
DATA STRUCTURE
Primitive DS Non-Primitive DS
Integer
Linear Non Linear
Float
Char Array
Tre
Pointer Linked list e
Graph
s Stack
Queue
• Queue is a linear data structure.
• It is used for temporary storage of data
values.
• A new element is added at one end called
rear end.
• The existing elements deleted from the
• other end called front
First-in-First-out end.
property. rear
34 12 53 61 9 23 42
front
Operations on Queue
1.Insertion :
Placing an item in a queue is called “insertion
or enqueue”, which is done at the end of the
queue called “rear”.
Fron
Rea t
r
2.Deletion :
Removing an item from a queue is called
“deletion or dequeue” , which is done at
the other end of the queue called “front”.
Fron
Rea t
r
Array Representation of Queues
A[0] A[1] A[2] A[3]
A[4]
12 9 7 18
QUEUE
front
rear
fron rea
12 9 7 18 r
t 14
9 7 18 14
Queue after insertion of a new element
front rear
Queue after deletion of an
element
Algorithm to insert an element in queue
STEP-1 IF REAR= MAX-1 INITIALL
write OVERFLOW Y REAR =
go to step 4 -1
FRONT =-1
[end of if]
STEP-2 if REAR = -1
set
FRONT=REAR= 0
else
STEP-3 set QUEUE
set [ REAR
REAR =] = NUM
STEP- EXITREAR+1
4
Algorithm to delete an element from queue
STEP-1 If FRONT = -1 or FRONT > REAR
write UNDERFLOW
Else
set VAL = QUEUE
[ FRONT ] set FRONT =
FRONT + 1
[end of if]
STEP-2 EXIT
Linked Representation of Queues
9 300 7 350 4 360 2 N Front = 290
Rear = 360
290 Front 300 350 360 rear
Linked queue
1. Deque
2. Circular Queue
3. Priority Queue
DEQUES
1.Deque stands for double ended
queue. 2.Elements can be inserted or
deleted at either end.
3. Also known as head-tail linked list.
insertion insertion
34 12 53 61 9
fron rea
t deletion r deletion
Types Of Deque
insertion
1.Input restricted deque:
34 12 53 61 9
fron rea
t deletion r deletion
2. Output restricted
deque: insertion
insertion
34 12 53 61 9
fron rea
t deletion r
CIRCULAR QUEUES
INITIALLY
FRONT= -1
REAR= 0
Algorithm to delete an element from queue