The priority queue

As queues are largely applied in Computer Science and also in our lives, there are some modified versions of the default queue we implemented in the previous topic.

One modified version is the priority queue. Elements are added and removed based on a priority. An example from real life is the boarding line at the airport. First class and business class passengers have priority over coach class passengers. In some countries, elderly people and pregnant women (or women with newborn children) also have priority for boarding over other passengers.

Another example from real life is the patient's waiting room from a hospital (emergency department). Patients that have a severe condition are seen by a doctor prior to patients with a ...

Get Learning JavaScript Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.