sort(起始地址,终止地址,排序函数)
注意排序的区间是[起始地址,终止地址),左闭右开
代码
#include <iostream>
#include <string>#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
bool cmp(int a,int b);
int main()
{
int x[10] = {1,3,2,5,4,7,6,8,0,9};
sort(x,x+10,cmp);
for(int i=0;i<10;i++)
cout << x[i] << ' ';
return 0;
}
bool cmp(int a,int b)
{
return a>b;
}