cmp和sort

结构体中的比较 

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;    //定义方法

  关于 vector q【】的sort

 基本原理 :queue of sort is concerned about 0,thus  n is just the num,from 0 ;   

                    so if 1.....n (+1,+n+1)  ; 

                    sort(q.begin(),q.begin()+q.size() ) that's all; not -1;

  

 

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