a={5,3,2,1,6 };
sort(a,a+n);
//输出是1 2 3 5 6
bool cmp(int a,int b)
{
return a>b;
}
a={5,3,2,1,6}
sort(a,a+5,cmp)
a={5,3,2,1,6}
sort(a,a+5,greater<int>()) //注意后面的()不能少
struct Point{
int x,y;
}p[maxn];
bool cmp(Point a,Point b)
{
return a.x<b.x;//按照x从小到大排序
}
struct Point{
int x,y;
bool operator< (const Point& a) const
{
return x>a.x;//x从大到小排序
}
}p[maxn];
sort(p,p+n);
int num[10]={14,10,56,7,83,22,36,91,3,47};
priority_queue<int> q;
int num[10]={14,10,56,7,83,22,36,91,3,47};
priority_queue<int,vector<int>,greater<int> > que;/////采取最小优先策略,即按从小到大的顺序排列
priority_queue<int,vector<int>,less<int> > que1; ////采取最大优先策略,即按从大到小的顺序排列
struct student
{
string name;
float score;
/////重载<运算符来实现改变优先规则
bool operator < (const student &s) const
{
//////按score由小到大排列
return score>s.score
//////按score由大到小排列;
//return score<s.score;
}
};
原文地址:http://www.cnblogs.com/gt123/p/3853737.html