Unit 3 Queue
Unit 3 Queue
Laxman Bhandari
MSc.CSIT , CDCSIT-TU
03/17/2024 By:Laxman Bhandari 1
Unit 3: Queue (3 hrs.)
1 2 3
Rear
Figure: Queue
• The queue data structure follows the FIFO (First
In First Out) principle,
i.e. the element inserted at first, is the first element to be removed from the
queue.
03/17/2024
operation front pointer is By:Laxman
incremented.
Bhandari 7
Contd…
• Enqueue:
Front =0 Rear = 5
12 9 7 18 14 36
Front =0 Rear = 5
12 9 7 18 14 36
Front =0 Rear = 6
12 9 7 18 14 36 45
Front =0 Rear = 6
12 9 7 18 14 36 45
Fig: Queue before deletion of an element
Front =1 Rear = 6
9 7 18 14 36 45
– Linear Queue
– Circular Queue
– Priority Queue
7 18 14 36 45 34 20 80
90 20 7 18 14 36 45 34 20 80
90 20 7 18 14 36 45 34 20
Front =2 Rear = 9
7 18 14 36 45 34 20 90
Front =Rear=-1
• If the queue is not empty and front = rear, then after deleting the element
at
• the front the queue becomes empty and so front and rear are set to –1.
• Front =Rear = 9
90
• If the queue is not empty and front = MAX–1, then after deleting
the
element at the front, front is set to 0.
Rear = 5 Front =9
80 70 7 18 14 36 90
• If we are using a sorted linked list, then the element with the higher priority
will precede the element with the lower priority. when two elements have
the same priority the elements are arranged and processed on FCFS
principle. Lower priority number means higher priority value.
node of the list will be deleted and the data of that node
will be processed first.
• What is priority queue? How it is best implemented? Explain with suitable example
program.