Sir for A.age<B.age.Output should be persons having lesser age the highest priority.But its coming out to be age in descending order.
#include
#include
#include
using namespace std;
class Person
{
public:
string name;
int age;
Person()
{
}
Person(string a,int b)
{
name=a;
age=b;
}
};
class PersonCompare
{
public:
bool operator()(Person A,Person B)
{
return A.age<B.age;
}
};
int main()
{
int n;
cin>>n;
priority_queue<Person,vector,PersonCompare> pq;
for(int i=0;i<n;i++)
{
string name;
int age;
cin>>name>>age;
Person p(name,age);
pq.push§;
}
int k=3;
for(int i=0;i<k;i++)
{
Person p=pq.top();
cout<<p.name<<" "<<p.age<<endl;
pq.pop();
}
}