sort排序默认是从小到大排序
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a<b;
}
int cmp1(int a,int b)
{
return a>b;
}
int main()
{
int a[]={1,5,2,3,7};
///从小到大排序
sort(a,a+5,cmp);///sort(a,a+5);也是默认排序
for(int i=0;i<5;i++){
cout<<a[i]<<" ";
}
cout<<endl;
///从大到小排序
sort(a,a+5,cmp1);
for(int i=0;i<5;i++){
cout<<a[i]<<" ";
}
}