Search code examples
c++priority-queue

I'm declaring a custom priority queue of pair< pair<int,int> , int >, how do I clear it?


bool comp(pair< pair<int,int>, int > left, pair< pair<int,int>, int > right) { return left.second > right.second;}
//auto cmp = [](pair< pair<int,int>, int > left, pair< pair<int,int>, int > right) { return left.second > right.second;};
priority_queue< pair< pair<int,int>, int >,vector< pair< pair<int,int>, int > >, std::function<bool(pair< pair<int,int>, int >,pair< pair<int,int>, int >) > > q(comp);

How should I clear it? I get error when I try to clear. using this function :

template <class T, class S, class C>
void clearpq2(priority_queue<T, S, C>& q){
    q=priority_queue<T, S, C>();
}

Solution

  • Try

    q = priority_queue< pair< pair<int,int>, int >,vector< pair< pair<int,int>, int > >, std::function<bool(pair< pair<int,int>, int >,pair< pair<int,int>, int >) > > (comp);