-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpriorityQueue_2.cpp
More file actions
51 lines (44 loc) · 1.04 KB
/
priorityQueue_2.cpp
File metadata and controls
51 lines (44 loc) · 1.04 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
#include <iostream>
#include <queue>
/*inbuilt priority queue bhi queue me hi rehta hai
bs class me hm priority_queue<datatype> is trah initiate krenge
by default max priority queue bnta hai means
functions:
empty()
size()
push(element)
T top()
pop() - lekin isse element return nhi hoga
*/
using namespace std;
int main()
{
priority_queue<int> pq; //normal max heap
pq.push(167);
pq.push(78);
pq.push(87);
pq.push(56);
pq.push(45);
pq.push(20);
cout<<"size: "<<pq.size()<<endl;
cout<<"Top: "<<pq.top()<<endl;
while(!pq.empty()){
cout<<pq.top()<<endl;
pq.pop();
}
//to make a min heap
priority_queue<int,vector<int>,greater<int> > pqmin;
pqmin.push(167);
pqmin.push(78);
pqmin.push(87);
pqmin.push(56);
pqmin.push(45);
pqmin.push(20);
cout<<"size: "<<pqmin.size()<<endl;
cout<<"Top: "<<pqmin.top()<<endl;
while(!pqmin.empty()){
cout<<pqmin.top()<<endl;
pqmin.pop();
}
return 0;
}