(转)C/C++sort从大到小排序
(2019-07-23 20:21:06)分类: c/cpp |
C/C++ sort从大到小排序
#include
#include
using namespace std;
bool cmp(int a,int b){
return a
> b;
}
int main(){
int a[] =
{5,3,7,3,9,4};
sort(a,a+6,cmp);
for(int i =
0;i < 6;i ++){
cout<<a[i]<<" ";
}
return
0;
}
方法:重写sort中的cmp方法
sort方法默认的是从小到大排序,如果希望能按照从大到小的方式排序,需要重写cmp方法
原文:https://blog.csdn.net/pack__pack/article/details/80773972
#include
using namespace std;
bool cmp(int a,int b){
}
int main(){
}
后一篇:(转)C++中inline的用法