C++ sort函数
来源:互联网 发布:iis绑定域名 编辑:程序博客网 时间:2024/06/17 22:50
sort函数:#include <algorithm>,默认从小到大,如果降序可写第三方函数进行排序,EXP:sort(array,array+n,cmp)
普通排序,降序
2.结构体排序,a升,b降,c降
1.普通排序,升序
#include <iostream>#include <algorithm>using namespace std;int main(){ int a[10]={7,3,4,6,5,1,2,9,8,0}; sort(a,a+10); for(int i=0;i<10;i++) cout<<a[i]<<" "; return 0;}OUTPUT:0 1 2 3 4 5 6 7 8 9
普通排序,降序
#include <iostream>#include <algorithm>using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ int a[10]={7,3,4,6,5,1,2,9,8,0}; sort(a,a+10,cmp); for(int i=0;i<10;i++) cout<<a[i]<<" "; return 0;}OUTPUT:9 8 7 6 5 4 3 2 1 0
2.结构体排序,a升,b降,c降
#include <iostream>#include <algorithm>using namespace std;struct data{ int a; int b; int c;};bool cmp(data x,data y){ if(x.a!=y.a) return x.a<x.y; if(x.b!=y.b) return x.b>y.b; if(x.c!=y.c) return x.c>y.c;}int main(){ ..... sort(array,array+n,cmp); return 0;}
转载自C/C++程序员之家
本文链接地址: sort函数
0 0
- C++sort 函数用法
- C++sort 函数用法
- C++sort 函数用法
- C++Sort函数用法
- C++sort函数
- C/C++sort函数用法
- C++sort函数的用法
- C++sort函数的用法
- [C++]排序函数sort()用法
- C++sort函数使用总结
- C/C++中的sort()函数,,,,,,,
- C++sort函数的用法
- C++sort函数的用法
- C++sort函数的用法
- C++sort函数的用法
- C ++排序函数sort(),qsort()
- C++sort函数的用法
- C++sort()函数的用法
- WIFI Architecture on Android 4.2
- leetcode: Reverse Integer
- 如何在Hadoop中控制Map的数量
- 1137 . 矩阵乘法
- 自学Node.js: WebStorm+Node.js开发环境的配置
- C++ sort函数
- 漂亮的代码
- java中的空串与null串
- 1136 . 欧拉函数
- ZOJ 3396 Conference Call
- iphone数据库(sqlite3)的用法操作oc,xcode
- 2014.2.22 Java 容器
- Myeclipse创建maven web工程及配置
- html 的 cellpadding 与 cellspacing