C++中的sort使用
来源:互联网 发布:教化妆的软件 编辑:程序博客网 时间:2024/06/05 09:29
默认从小到大排序
0,2,3,4,4,5,6,7,8,9,
9,8,7,6,5,4,4,3,2,0,
请按任意键继续. . .
#include <iostream>using namespace std;#include <algorithm>/*bool complare(int a, int b){return a > b;}*/int main(){int arr[10] = { 3,4,2,7,9,4,5,6,8,0 };for (int i = 0; i < 10; i++){cout << arr[i] << ",";}cout << endl;sort(arr, arr + 10);for (int i = 0; i < 10; i++){cout << arr[i] << ",";}cout << endl;system("pause");return 0;}3,4,2,7,9,4,5,6,8,0,
0,2,3,4,4,5,6,7,8,9,
请按任意键继续. . .
从大到小
#include <iostream>using namespace std;#include <algorithm>bool complare(int a, int b){return a > b;}int main(){int arr[10] = { 3,4,2,7,9,4,5,6,8,0 };for (int i = 0; i < 10; i++){cout << arr[i] << ",";}cout << endl;sort(arr, arr + 10,complare);for (int i = 0; i < 10; i++){cout << arr[i] << ",";}cout << endl;system("pause");return 0;}3,4,2,7,9,4,5,6,8,0,
9,8,7,6,5,4,4,3,2,0,
请按任意键继续. . .
阅读全文
0 0
- C++中的sort使用
- C/C++中的sort()函数,,,,,,,
- C++sort函数使用总结
- C&C++中的qsort和sort库函数
- c/c++中的sort()与qsort()用法
- 使用STL中的泛型算法sort
- C#中的Array.Sort()的使用
- sort 在field group中的使用
- list中的Sort、Exists方法使用
- python中的sort方法使用详解
- Shell中的sort排序命令的使用
- python中的sort方法使用详解
- python中的sort方法使用详解
- Algorithm头文件中的sort函数使用
- 关于javascript中的sort()方法的使用
- python中的sort方法使用详解
- python中的sort方法使用详解
- java中的排序sort()函数的使用
- 常指针(指向常量的指针),指针常量,指向常量的常指针
- 大数乘法的分治策略C++实现
- USACO Section 1.1 Broken Necklace
- SpringMVC 的Model值传到JSP页面中,用EL表达试取不到值
- 高通camera驱动分析
- C++中的sort使用
- 二分--刷票
- Hibernate中session.get和session.load执行是有什么区别
- logRegres 源码
- 数据结构---平衡二叉树
- AndroidStudio升级gradle插件版本到2.3.1异常
- 偶然
- Tempter of the Bone
- 《大型网站技术架构:核心原理与案例分析》拜读总结,第十章——随需应变:维基百科高性能架构设计分析