-
Notifications
You must be signed in to change notification settings - Fork 17
/
priority queue stl implementation of comparator class(part -2).cpp
65 lines (56 loc) · 1.72 KB
/
priority queue stl implementation of comparator class(part -2).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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include<queue>
#include<cstring>
using namespace std;
class Personcompare{
public:
bool operator()(Person A,Person B)
{
return A.age < B.age;
}
};
class Fun{
public:
void operator()(string s)
{
cout<<"having fun with strings "<<s;
}
};
class Person{
public:
string name;
int age;
Person()
{
}
Person(string n, int a)
{
name = n;
age = a;
}
};
int main()
{
Fun f;//constructor
f("C++");//overloaded function call()operator where f is an object.
priority_queue<Person,vector<Person>,Personcompare> pq;
int n;
cout<<"enter the no. of persons: ";
for(int i=0;i<n;i++)
{
string name;
int age;
cout<<"name and age "<<i;
cin>>name>>age;
Person p(name,age);
pq.push(p);
}
int k;
for(int i=0;i<3;i++)
{
Person p=pq.top();
cout<<p.name<<" "<<p.age<<endl;
pq.pop();
}
return 0;
}