Priority queues
A priority queue makes it possible to extend the concept of a queue by setting a priority for each element in the queue. The elements are dequeued starting from those with the highest priority. Within each priority, you dequeue items in the same order as in a standard queue. It is worth mentioning that the priority can be specified simply as an integer value. It depends on the implementation whether smaller or greater values indicate higher priority. In the book, it is assumed that the highest priority is equal to 0
, while lower priority is specified by 1
, 2
, 3
, and so on.
Imagine a priority queue
If you want to better visualize a priority queue, close your eyes for a moment and imagine yourself going on the greatest vacation of your life. All passengers are already lining up at the gate, including you, but it turns out that right next to it, there is a much shorter queue for people who have a gold airline card. There are only 3 people in that line, and in yours...