The API
From the outside, a Priority Queue looks exactly like a normal Queue. It has `push(val)`, `pop()`, `top()`, and `empty()`. The internal sorting magic is completely hidden from the user.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Before diving into Heaps, understand the abstraction: A Priority Queue is simply a Queue where every element has a "priority score". Elements with higher scores skip the line.
From the outside, a Priority Queue looks exactly like a normal Queue. It has `push(val)`, `pop()`, `top()`, and `empty()`. The internal sorting magic is completely hidden from the user.
By default in C++, `std::priority_queue` is a Max-Heap (the largest number is popped first). By passing a custom comparator (`std::greater`), you can easily flip it into a Min-Heap (smallest first).
You aren't limited to integers! You can store complex objects (like `Patient { name, severity }`) and define your own custom sorting logic to determine which patient gets treated first.