January 2018
Intermediate to advanced
332 pages
7h 36m
English
A priority queue is operationally similar the simple queues, that is, they support the same API, but there is a small addition to the data that they hold. Along with the element (your data), they can also persist a priority, which is just a numerical value indicating the priority of your element in the queue.
Addition or removal of these elements from the queue is based on priority. You can either have a minimum priority queue or a maximum priority queue, to help establish whether you are adding elements based on increasing priority or decreasing priority. We will take a look at how the add() method can substitute the add() method of the simple queue that we defined earlier:
add(newEl) { let queue = items.get(pqkey); let
Read now
Unlock full access