Pair inside priority queue

前端 未结 2 1781
别跟我提以往
别跟我提以往 2021-01-30 14:00

I am trying to store pairs in priority queue and I am using a compare function that compares second value of each pair.

#include
#include

        
相关标签:
2条回答
  • 2021-01-30 14:44

    This is what priority_queue looks like:

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

    In other words, CompareDist should be the third argument and the second argument should be the container (which has value_type), like the following:

    priority_queue<pair<int,int>,vector<pair<int,int>>,CompareDist> pq;
    

    Notice also, that priority_queue is what is called a "container adaptor". Another container is used as the underlying container and the priority_queue has special members functions for accessing it. Another example of a container adaptor would be std::stack.

    0 讨论(0)
  • 2021-01-30 14:52
    priority_queue<pair<int,int>,vector<pair<int,int>>,CompareDist> pq;
    

    you need to provide second argument for the inbuilt template of priority_queue.

    0 讨论(0)
提交回复
热议问题