how to use comparator funtion in priority queue in c++

[ad_1]

how to use comparator funtion in priority queue in c++
// suppose you want to apply comparator on pair 
// declaration of priority queue
priority_queue, vector>, myComp> pq;
// here myComp is comparator
struct myComp {
  bool operator()(
    pair& a,
    pair& b)
  {
    return a.first > b.first;
    // can write more code if required. depends upon requirement.
  }
};
// another way
 auto compare = [](int lhs, int rhs){
  return lhs < rhs;
};

priority_queue, decltype(compare) > pq(compare);

[ad_2]

Please follow and like us:
Content Protection by DMCA.com