Merge k sorted lists

am not able to properly use priority queue

please help me doing it

hello @gulatigarvita08

check now->

now u need to define ur own comparator in place of using inbuild comparator of priority queue becuase inbuilt comparator will compare pointer address instead of their values

u can refer gfg for the same.

why aren’t we making compare class in merge k sorted arrays problem

one more doubt … why we always pass pointers as parameters to overloaded function ()

here we are using pairs, priority works on pairs, it uses first value of pair for comparision.

in case of list we are passing pointers because we have stored pointers in our priorirty queue. if we would have stored something else then in that case we need to pass that datatype in our overlaoded operator

thats not address , it is called refrence variable in c++.
we are doing that to avoid creating copy of object.

read difference b/w pass by value and pass by refrence

oh sorry :sweat_smile:

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.