Cpp Priority_queue_customize

Techniques for customizing priority_queue in C++ STL

Basic

priority_queue is a container adaptor in C++ STL. It provides an order for elements in queue, taking the advantage of the data structure heap. The comparing (the order to keep the queue) can be customized and it is very useful in some cases to make algorithms more quick and efficient. Here are some summarize about the customization, as well as some of mt own understandings.

Here is the complete initializing template for priority_queue:

template<
    class T,
    class Container = std::vector<T>,
    class Compare = std::less<typename Container::value_type>
> class priority_queue;

Priority_queue is very supportive solving problems using greedy algorithms. But sometimes the problems are tricky to use a integer only, so priority queue with self-designed order is very sharp for these occasions.

Some contents are based on cppreference and some blogs on Internet.