Queue Unit3
Queue Unit3
Queue
Shikha Sharma
Topics Covered
2
Topics
• Queue
• Circular queue
• Deque
• Priority Queue
• Operations on Queue
3
Objectives
4
Objectives
5
Queue Data Structure
6
Introduction
• The element can be added into the rear of the queue and can be
8
Representation of Queue
NORMQUEINS(FRONT,REAR,ITEM)
• Step-5: Exit
Algorithm for popping an element from the queue
NORMQUEDEL(FRONT,REAR,ITEM)
• Step-5: Exit
Disadvantage of Queue
• Example:
Types of queues and Operations on Queues
Introduction
• By making some variations in the simple queue, three types of queues can
be formed:
• Circular queue
• Priority queue
Circular Queue
CIRQUEINS(FRONT,REAR,ITEM,N)
• Step-4: Exit
Algorithm for deleting element from circular queue
CIRQUEDEL(FRONT,REAR,ITEM,N)
• Step-1: if (FRONT is equal to -1)
• Display “Queue is empty” or “UnderFlow”
• Exit
• Step-2: Set ITEM = Queue[FRONT]
• Step-3: if (REAR is equal to FRONT)
• SET : FRONT = -1
• SET : REAR = -1
• Else-IF FRONT==N-1 THEN Set FRONT=0
Else Set : FRONT = FRONT +1
• Step-4: Exit
Deque
• In the deque, you can insert and delete data elements from both sides of
the queue.
• If (left==right==NULL)
• Display “Queue Underflow”
• Exit
• Data_element = DEQUE [right]
• If (left == right)
• left = -1
• right = -1
• Else
• if(right== 0)
Set- right = Size-1
• Else
Set- right = right-1
• Exit
Algorithm for deleting the data element at left side of
a deque
• If (left==right==NULL)
• Display “Queue Underflow”
• Exit
• data_element = DEQUE [front]
• If(left == right)
• left = -1
• right = -1
• Else
• if (left == Size-1)
Set left = 0
• Else
left = left +1
• Exit
Priority Queue
• A priority queue is like any other queue with a priority associated with
• Insert
• Delete
Applications of Priority Queue
• Bandwidth management
• Dijkstra’s algorithm
• Printing services
2
Summary
• A few variations of queue are also available - circular queue, priority queue
and deque