Priority Queues
You learned about Queues, and discovered that the queue is a list in which items are processed first in, first out (FIFO). Essentially, this means that data is inserted only at the end of the queue, and data is accessed and removed only from the front of the queue. In accessing the queue’s data, we give precedence to the order in which the data was inserted.
A priority queue is a list whose deletions and access are just like a classic queue but whose insertions are like an ordered array. So we only delete and access data from the front of the priority queue, but when we insert data, we always make sure the data remains sorted in a specific order.
One classic example of where a priority queue is helpful is an application that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access