- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_priority_queue.cpp
More file actions
Latest commit
25 lines (20 loc) · 558 Bytes
/
Copy pathstd_priority_queue.cpp
File metadata and controls
25 lines (20 loc) · 558 Bytes
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
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
intmain()
{
std::vector<int> nums{2, 3, 6, 3, 9, 10, 23, 11, 67, 44};
std::priority_queue<int> maxHeap(nums.begin(), nums.end()); // by default It is max-heap
std::priority_queue<int, std::vector<int>, std::greater<int>> minHeap(nums.begin(), nums.end()); // min-heap
while (!maxHeap.empty()) {
std::cout << maxHeap.top() << "";
maxHeap.pop();
}
printf("\n\n");
while (!minHeap.empty()) {
std::cout << minHeap.top() << "";
minHeap.pop();
}
std::cin.get();
}