Hi. i want to pass to a priority queue some structs.
for example:
1 2 3 4 5 6 7
struct person
{
int age;
char sex;
sting name;
//etc
};
I want to push this. I want the compare to be first women and if 2 persons are women take the one with the smallest age. Can you help me write the template?
thank you so much
class personcompare
{
public:
booloperator() (const person& p1, const person& p2) const
{ // largest elements will be at top of priority queue
if(p1.sex == 'F' && p2.sex == 'M')
returntrue;
if(p1.sex == 'M' && p2.sex == 'F')
returnfalse;
// got to here then they are the same sex - youngest first ("largest" element)
return(p1.age > p2.age);
}
};