When should I use make_heap vs. Priority Queue?

There’s no difference in terms of performance. std::priority_queue is just an adapter class that wraps the container and the very same heap-related function calls into a class. The specification of the std::priority_queue openly states that.

By building a heap from an exposed std::vector and calling heap-related functions directly, you keep it open to the possibility of outside access, potentially damaging the integrity of the heap/queue. std::priority_queue acts as a barrier restricting that access to a “canonical” minimum: push(), pop(), top() etc. You can see it as self-discipline enforcing measure.

Also, by adapting your queue interface to the “canonical” set of operations, you make it uniform and interchangeable with other class-based implementations of priority queues that conform to the same external specification.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)