How to use comparator funtion in priority queue in c++ Code Example
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.
}
};