首页 > 其他 > 详细

3 种比较 cmp

时间:2019-10-27 22:36:07      阅读:75      评论:0      收藏:0      [点我收藏+]

结构体中的比较 

struct dian{
    int l,r;
    bool operator <(const dian &t)const
    {
        if(r==t.r) return l>t.l;
        return r<t.r; 
    }
}p[N];

sort的专用 cmp 

bool cmp1(const dian &a,const dian &b)const
{
     if(a.l==b.l) return a.r<b.r;
     return a.l<b.l;
}

 优先队列的cmp

struct cmp {     
  operator bool ()(int x, int y)     
  {        
     return x > y;   // x小的优先级高       //也可以写成其他方式,如: return p[x] > p[y];表示p[i]小的优先级高
  }
};
priority_queue<int, vector<int>, cmp> q;    //定义方法

 

  

 

3 种比较 cmp

原文:https://www.cnblogs.com/Lamboofhome/p/11749020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!