Priority Queue Comparison

后端 未结 6 1766
心在旅途
心在旅途 2021-02-05 08:40

I\'m trying to declare a priority queue in c++ using a custom comparison function...

So , I declare the queue as follows:

std::priority_queue

        
6条回答
  •  逝去的感伤
    2021-02-05 08:58

    You can use C++11 lambda function. You need to create lambda object, pass it to the template using decltype and also pass it to the constructor. It looks like this:

    auto comp = [] (int &a, int &b) -> bool { return a < b; };
    std::priority_queue, decltype(comp) > pq (comp);
    

提交回复
热议问题