Module 7 Queue
Module 7 Queue
Queue
Queues
• Queue is another linear data structure used for storing data
• Items are inserted and deleted as per the FIFO (first-in-first-out) principle
• The first element inserted in the queue is the first element to be deleted
• Unlike Stack, Queue is open from both the ends
• Insertion takes place from one end called front
• Deletion takes place from another end called rear
• Applications
• Queue formed for bus/ticket/elevator
• CPU scheduling
• Printer scheduling
Queue Operations
• Fundamental ADT operations:
• Enqueue(x): Inserts an element 𝑥 at the rear of the queue
• Dequeue(): Deletes an element from the front of the queue
Dequeue Enqueue
front rear
Queue Implementation using Array
• The above space cannot be reused until the queue is empty (front = rear =0)
• Elements with the same priority are processed according to the order in which
they were added
• Applications
• Priority queue at airport check-in counters
• Priority queue in a time-sharing system
Priority Queue
• Linked List Representation: Node
key priority next
head
GGG 5 X
Lower the Priority Number, the Higher the Priority
References
• Saymour L., “Data Structures”, Schaum’s Outline Series, McGraw Hill,
Revised First Edition
• Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford
Stein, “Introduction to Algorithms”, The MIT Press
• Sahni, S., “Data Structures, Algorithms, and Applications in C++”,
WCB/McGraw-Hill