优先级队列priority_queue 自定义比较函数cmp

便捷方法

struct Node
{
    int x,y;
    bool operator <(Node a) const  {  return y < a.y; }
    bool operator >(Node a) const  {  return y > a.y; }
};
    priority_queue<Node> A;                    //大根堆
    priority_queue<Node, vector<Node>, greater<Node> > B;    //小根堆 

常用方法

struct cmp{
    bool operator()(Node a,Node b) { return  a.val > b.val; }
};

  

posted @ 2020-11-23 20:09  tao10203  阅读(645)  评论(0)    收藏  举报