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
- Making one
- push and emplace
- top
- pop
- size and empty
- swap
- What it does not have
- Emptying one: three ways
- The order: three template arguments
- The smallest first: greater<T>
- The negated-key trickIntermediate
- Pairs: first, then second
- A struct: operator< or a comparator structIntermediate
- The heap algorithms on an open vector
- Every cost in one table, and the measurement