priority_queue 中存放pair时,自定义排序的写法

struct cmp
    {template 
        bool operator()(T const &left, U const &right)
        {
        // 以 second 比较。输出结果为 Second 较大的在前 Second 相同时,先进入队列的元素在前。
            if (left.second < right.second)
                return true;
            return false;
        }
    };
    // new.
    priority_queue, vector>, cmp> pq;

你可能感兴趣的:(priority_queue 中存放pair时,自定义排序的写法)