Skip to content

priority_queue - Heap

1
#include <priority_queue>

Construct

1
2
3
4
5
// Max Heap
priority_queue<int> pq;

// Min Heap
priority_queue<int, vector<int>, greater<int>> pq;

Operations

1
2
3
4
5
6
7
// Push
pq.push(1);

// Access
auto x = pq.top();

pq.pop();

In <algorithm>

Use