Learn C++ STL

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

Module 7 · priority_queue: The Biggest One Comes Out First

Every priority_queue Operation, One by One, With Its Cost

Free with an accountReading

Kenji keeps his game's high scores in a priority_queue<int> and wants to print them. He writes the loop that worked on every vector, for (int x : pq), and GCC 12 refuses: error: no matching function for call to 'begin(std::priority_queue<int>&)'. A priority_queue shows only its top, on purpose. This lesson lists every call it has, with its cost, then what it refuses, and every way to choose its order.

Checking what this lesson needs for you…

What is inside Every priority_queue Operation, One by One, With Its Cost

  1. Making one
  2. push and emplace
  3. top
  4. pop
  5. size and empty
  6. swap
  7. What it does not have
  8. Emptying one: three ways
  9. The order: three template arguments
  10. The smallest first: greater<T>
  11. The negated-key trickIntermediate
  12. Pairs: first, then second
  13. A struct: operator< or a comparator structIntermediate
  14. The heap algorithms on an open vector
  15. Every cost in one table, and the measurement