#include<algorithm> 快排 nlogn
sort(first,last,cmp)
自定义排序:
(1)自定义比较函数cmp
bool cmp(int a,int b)
{
return a>b;//由大到小
}
sort(a,a+n,cmp);
(2)重载比较运算符<
bool operator<(const Student& s1,const Student& s2)
{
if(s1.age==s2.age)
return s1.name<s2.name;
else return s1.age>s2.age;
}
sort(a,a+n);
(3)声明比较类
struct cmp
{
bool operator() (const Student& s1,const Studenet& s2)
{
if(s1.age==s2.age)
return s1.name<s2.name;
else return s1.age<s2.age;
}
};
sort(a,a+n,cmp());
e.g.
st