Priority Queue STL 02 | Comparator Class

  1. Didn’t understand declaration of priority queue, which is

    priority_queue<person,vector,personCmp> pq;

    on line no 40 in the video.

selected line here in my code

  1. Also didn’t understand personCmp class.

hi @saniyaainamdar,
first - here a priority queue is made of type vector, when u dont make it with primitive data type then it is defined like this only.

second - as it is not primitive data type like int, float
say compiler understand how to compare 10 and 20 but what about person who has attributes {name,age} how does compiler decides to compare so u name a personCmp class here u say compare on these attributes

u can read https://www.geeksforgeeks.org/stl-priority-queue-for-structure-or-class/
for more

Got it. Thank You…!!

@saniyaainamdar, please mark as resolved

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.