Learn C++ STL

Lesson 4 of 9 · priority_queue: The Biggest One Comes Out First

Module 7 · priority_queue: The Biggest One Comes Out First

When to Use priority_queue, and When a Sort or a set Is Better

Free with an accountReading

Kenji pushes a million sensor readings into a priority_queue, only to print them all, largest first, once. Maria keeps her lab's task list in a vector, and before every take she scans it for the most urgent task. Both programs print the right answer. Amara asks each of them one question: what did the job need?

Checking what this lesson needs for you…

What is inside When to Use priority_queue, and When a Sort or a set Is Better

  1. Four questions about the job
  2. The comparison chart
  3. The decision flowchart
  4. Kenji's million readings: one sort against the heap
  5. Values that keep arriving: four containers raced
  6. Both ends at once
  7. When not to use a priority_queue