1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <queue> #include <functional>
std::priority_queue<T, Container, Compare> pq;
std::priority_queue<int> pq1;
std::priority_queue<int, std::vector<int>> pq2;
std::priority_queue<int, std::vector<int>, std::greater<int>> min_pq;
struct Compare { bool operator()(int a, int b) { return a > b; } }; std::priority_queue<int, std::vector<int>, Compare> custom_pq;
std::vector<int> vec = {3, 1, 4, 1, 5}; std::priority_queue<int> pq3(vec.begin(), vec.end());
pq.push(10); pq.emplace(20);
pq.top();
pq.pop(); pq.empty(); pq.size();
|