Priority queue
A priority queue is a container that uses a heap to keep a prioritized list of the elements within the container. Priority queues are helpful because you can order the result set by priority. Priority queues are often used for many practical applications, from load balancing web requests to data compression, to Dijkstra's algorithm.
In our priority queue example, we create a new priority queue and insert a couple of different programming languages that have a given priority. We start with Java being the first priority and then Go becomes the first priority. PHP gets added and Java's priority gets pushed down to 3. The following code is an example of a priority queue. Here, we instantiate the necessary requirements, create a ...
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