samedi 3 novembre 2018

How the comparator in priority_queue is different from the std :: sort() comparator ? How to implement comparator for both?

I couldn't get the comparator in std:: priority_queue.

std::priority_queue<pii, std::vector<pii >, myComparator> pq;

using:

class myComparator
{
public:
    int operator() ( const ppi &p1, const ppi &p2 )
    {
        return p1 . second > p2 . second;
    }
};

here ppi is

#define ppi std::pair<std::pair<int, int>,int>


And how it is different from the comparator in std:: sort. Below work for std:: sort but no for std:: priority_queue

bool myComparator ( const pii &p1, const pii &p2 )
{
    return p1 . second > p2 . second;
}

Aucun commentaire:

Enregistrer un commentaire