A queue is a data structure where elements are added at the rear and removed from the front. There are two main types of queues: a normal queue where insertion is at the rear and deletion is at the front, and a deque (double-ended queue) where elements can be inserted or removed from either end. A deque can be implemented using a circular linked list to allow additions and removals from both ends.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
74 views24 pages
Queue
A queue is a data structure where elements are added at the rear and removed from the front. There are two main types of queues: a normal queue where insertion is at the rear and deletion is at the front, and a deque (double-ended queue) where elements can be inserted or removed from either end. A deque can be implemented using a circular linked list to allow additions and removals from both ends.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24
QUEUES
QUEUES
•The queue is another data structure.
• A physical analogy for a queue is a line at a
bank. When you go to the bank, customers go to the rear (end) of the line and customers come off of the line (i.e., are serviced) from the front of the line. QUEUES
Like a stack, a queue usually holds things of
the same type. The main property of a queue is that objects go on the rear and come off of the front of the queue. QUEUE IMPLEMENTING QUEUE IMPLEMENTING QUEUE IMPLEMENTING QUEUE QUEUE
• In a normal queue insertion operation can be
performed at one end (rear end)
• And deletion operation can be performed at
another end (front end) QUEUE
•In a queue push & pop operations can be
performed in different ways also, based on these methods the queue’s are further classified into
– Dequeue – Priority Queue QUEUE - DEQUEUE
Dequeue (Double ended Queue)
•It allows insertion & deletion at both ends
•Dequeue can be:-
-Input Restricted - Output Restricted DEQUEUE
– In the I/P restricted dequeue insertion is done at rear
end & deletion can be done at both ends.
– In the O/P restricted dequeue deletion is done at
front end & insertion can be done at both ends. Implementing I/P restricted dequeue
– Display options for push & pop
Implementing I/P restricted dequeue
– For Push operation:
• Increase rear & place the item Implementing I/P restricted dequeue
– For pop operation:
• Display options to pop (Rear/Front) • Rear: Pop the item by decreasing the rear value • Front: Pop the item by increasing front value Implementing O/P restricted Dequeue
– Display options for push & pop
Implementing O/P restricted Dequeue
– For Push Operation
• Display option to push (Rear / Front) • Rear: Push the item by increasing rear • Front: Push the item by decreasing front Implementing O/P restricted Dequeue
– For pop operations
• Front value must be greater than “0” otherwise overflow • Delete the item by increasing the front value DEQUEUE IMPLEMENTATION
Implementing Dequeue using link list
– Link list must be circular link list
DEQUEUE IMPLEMENTATION
Using Doubly Link List :
•If a structure contains two self referential member
then it can be used to construct DLL.
• In a SLL the last node contains Null in its next ref
field. DEQUEUE IMPLEMENTATION
•In a DLL the last node contains Null in its next ref & the first node contains Null in its previous ref field.
•A SLL is a one way transversal List, in this list starting
from any node you can reach to last node. DEQUEUE IMPLEMENTATION
•A DLL is two way transversal, in this starting from any
node we can reach to the beginning or end of list.
•If we can reach to the same node by traversing all
nodes of the list then list is having circular reference. DEQUEUE IMPLEMENTATION DEQUEUE IMPLEMENTATION DEQUEUE IMPLEMENTATION