Priority queue for custom class

why did we need to pass vector as a parameter to priority_queue declaration ??

we passed PersonCompare object how that can call one of its class function operator itself, we did not call operator( )

Hi… can u share the code u are referring to

it in heaps 16 lecture - Priority queue for custom class
i am having problems in the lecture so i did not code it

that is what I am asking… what doubt u are having???

class PersonCompare{
public:
      bool operator ()(Person A, Person B)
      {
              return A.age >B.age ;
      }
};

priority_queue< Person, vector<Person>, PersonCompare > pq;

why did we need to pass vector<person> as a parameter in priority_queue declaration ??

we passed PersonCompare how that can call one of its class function operator itself as we did not call operator( )

and is it necessary to overload with () this operator to make a comparision

it is just used for using comparator function… basically making the priority queue min heap…

toh hum compare function kisi aur operator ko overload kr skte h ??

compare(int a, int b)
{
     return a>b;
}

aur mujhe ye kabhi smaj nii aya ki ye compare function agar as parameter pass ho kahi
toh yeh ascending order dega ya descending ???
ye fix h kya ??

compare(int a, int b)
{
return a>b;
}
this will give descending order…

agar as compare as parameter pass kr rhe toh hamesha descending dega ??

compare(int a, int b)
{
return a<b;
}
yha a < b will give ascending order…

han ascending dena chahiye
lekin jab print kra rhe h toh maxmimum wala pehle print ho rha h matlab desceding de rha h

kha pe… code share kro…

@Vaibhav277

refer this https://ide.codingblocks.com/s/269164

bhai m vahi toh puch rha hu
tumne iss siign pe ‘<’ ascending kaha tha
lekin ispe descending de rha h

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.