4 Comments
User's avatar
⭠ Return to thread
Raaka's avatar

It has alway been very counter-intuitive to me that when you write a custom lambda (in this case left.size() > right.size()) for priority_queue, it pops out smaller elements first. I always have to remind myself “It’s the other way around”. I think I even came up with a mental picture to memorize that.

Do you have a better way to remember this? Or a technical detail that I couldn’t find.

Šimon Tóth's avatar

It's not much better, but you can remember that it is a max-heap (same as the heap algorithms).