All lessonsOpen Open Open Open Open
4. Stacks & Queues
Priority queues and heaps intro
0 of 5 activities0%
Reading 1
Best-first retrieval
A priority queue serves the minimum or maximum key next, not insertion order.
Usually implemented as a binary heap: O(log n) push/pop, O(1) peek.
C++: priority_queue (max-heap by default).
priority_queue<int> pq;
pq.push(3); pq.push(10); pq.push(1);
cout << pq.top(); // 10Check 2
Default C++ PQ
std::priority_queue is by default a
Fill in 3
Tree shape
Try it 4
Max heap top
Push and print top.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Maximum of list
Read n and n ints. Print the maximum (priority-queue idea).
main.cpp
Loading editor…