-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPriority_Queue
More file actions
60 lines (48 loc) · 1.14 KB
/
Priority_Queue
File metadata and controls
60 lines (48 loc) · 1.14 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* *********************************************************
* KNOWLEDGE CENTER
* st::priority_queue
* Detailed Video Explanation: https://youtu.be/WhIcVlkZ19s
********************************************************** */
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
class Student{
int age;
int id;
// -- TODO
};
int main() {
/*
priority_queue<int> Q;
vector<int> v = {8, 1, 6, 4, 0, 7, 2, 9};
for(int x : v) Q.push(x);
while(!Q.empty()){
cout << Q.top() << " ";
Q.pop();
}
cout << endl;
*/
/*
priority_queue<int, vector<int>, std::greater<int>> Q;
vector<int> v = {8, 1, 6, 4, 0, 7, 2, 9};
for(int x : v) Q.push(x);
while(!Q.empty()){
cout << Q.top() << " ";
Q.pop();
}
cout << endl;
*/
auto cmp = [](int a, int b){
return a > b;
};
priority_queue<int, vector<int>, decltype(cmp)> Q(cmp);
vector<int> v = {8, 1, 6, 4, 0, 7, 2, 9};
for(int x : v) Q.push(x);
while(!Q.empty()){
cout << Q.top() << " ";
Q.pop();
}
cout << endl;
return 0;
}