sort(数组起始指针,数组末尾指针,排序规则);
默认从小到大排序。
排序规则可以省略,也可以自己写。
//这里自己写了排序规则
#include<algorithm>
struct S
{
int a;
int b;
}arr[10];
bool cmp(const S &a,const S &b)
{
return a.a<a.b;
}
sort(arr, arr + 10,cmp);
//这里在定义结构体时就重载了小于号
struct S{
int a;
int b;
bool operator < (const S &s1) const {
return a<s1.a;
}
}
}arr[10];
sort(arr,arr+10);