-
Notifications
You must be signed in to change notification settings - Fork 0
/
stlPQ.cpp
52 lines (39 loc) · 899 Bytes
/
stlPQ.cpp
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
/*
@Chiranjeevi
Date: 28-Jun-17
*/
/*
stl priority queue c++ using functor
*/
#include <iostream>
#include <queue>
using namespace std;
struct node{
int a, b;
};
struct compare {
bool operator()(node x, node y) {
if(x.a<y.a)
return true; // returning true means swap first and second argument i.e greater will be at first in the array , i.e array is max priority queue as index 0 stroes max element.
else
return false;
}
};
int main(){
priority_queue<node, vector<node>, compare> pq;
node x,y,z;
x.a=100;
x.b=11;
y.a=101;
y.b=12;
z.a=99;
z.b=100;
pq.push(x);
pq.push(y);
pq.push(z);
while(!pq.empty()){
cout<<pq.top().a<<endl;
pq.pop();
}
return 0;
}