sort函数形式
sort(begin, end) 默认从小到大排序
sort(begin, end, cmp)
举例
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 10010;
bool cmp(int x, int y){
//定义排序规则
//实现从小到大排序
return x < y;
}
int main(){
int n, a[maxn];
while (scanf("%d", &n) != EOF) {
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
sort(a, a + n, cmp);
for(int i = 0; i < n; ++i){
printf("%d ", a[i]);
}
printf("\n");
}
return 0;
}