【Eternallyc】C++中的sort排序函数
来源:互联网 发布:淘宝客a5淘客交流 编辑:程序博客网 时间:2024/05/21 13:57
如题,sort是一个很好用的排序函数,ACMer可以在刷题和比赛中可以直接调用,头文件为< algorithm >
下面给出sort函数的简单用法
#include <cstdio>#include <algorithm>using namespace std;int main(){ int i[5]={5,4,3,2,1}; sort(i,i+5); for(int a = 0;a < 5;a ++) printf("%d",i[a]); return 0;}
接下来是sort函数的复杂用法
#include <iostream>#include <algorithm>using namespace std;bool cmp(int a,int b){ return a>b;//降序,如果需要升序则为a<b; //或者 return b<a;降序,如果需要升序则为b>a;}int main(){ int i[10],n; cin>>n; for(int b = 0;b < n;b ++) cin>>i[b]; sort(i,i+n,cmp); for(int b = 0; b < n ;b ++ ) cout<<i[b]<<" "; cout<<endl; return 0;}
阅读全文
0 0
- 【Eternallyc】C++中的sort排序函数
- 【Eternallyc】qsort排序函数用法
- JavaScript中的排序函数sort
- [C++]排序函数sort()用法
- C ++排序函数sort(),qsort()
- C/C++中的sort()函数,,,,,,,
- linux内核中的排序接口--sort函数
- Python中的排序函数argsort,sort,sorted
- java中的排序sort()函数的使用
- C标准库中的快速排序(quick-sort)函数 [简单应用]
- C和C++库中的排序函数——sort与qsort解析
- 简单选择排序(Eternallyc)
- 【Eternallyc】函数PlaySound和sndPlaySound
- 排序函数sort()
- C++ Sort排序函数
- 排序函数sort
- sort函数降序排序
- sort()排序函数
- Java中ExecutorService和CompletionService区别
- js实现Java中的静态变量
- 如何更快的拉取国内的docker镜像
- 2017.7.8 C组总结
- MySQL中高级知识-MySQL架构介绍
- 【Eternallyc】C++中的sort排序函数
- Unable to instantiate application com.yunque.www.yunque.app.YunQuApplication: java.lang.ClassNotFoun
- 前端代码规范
- Integer’s Power HDU
- 一个完整的android项目需要哪些标配
- JAVA第一课第二节知识点
- Android PathEffect 效果使用
- ZJU1037-Gridland
- Spark参数配置