sort函数
2016-07-06 16:31
302 查看
头文件:
#include <algorithm>
using namespace std;
1.默认的sort函数是按升序排。对应于1)
sort(a,a+n);
2.可以自己写一个cmp函数
例如:
int cmp( const int &a, const int &b ){
if( a > b )
return 1;
else
return 0;
}
sort(a,a+n,cmp);
是对数组a降序排序,反之a<b升序
int cmp( const POINT &a, const POINT &b ){
if( a.x < b.x )
return 1;
else
if( a.x == b.x ){
if( a.y < b.y )
return 1;
else
return 0;
}
else
return 0;
}
sort(a,a+n,cmp);
是先按x升序排序,若x值相等则按y升序排
#include <algorithm>
using namespace std;
1.默认的sort函数是按升序排。对应于1)
sort(a,a+n);
2.可以自己写一个cmp函数
例如:
int cmp( const int &a, const int &b ){
if( a > b )
return 1;
else
return 0;
}
sort(a,a+n,cmp);
是对数组a降序排序,反之a<b升序
int cmp( const POINT &a, const POINT &b ){
if( a.x < b.x )
return 1;
else
if( a.x == b.x ){
if( a.y < b.y )
return 1;
else
return 0;
}
else
return 0;
}
sort(a,a+n,cmp);
是先按x升序排序,若x值相等则按y升序排
相关文章推荐
- 在线pdf转换成word文档的方法
- 解决tomcat内存溢出
- SQL 与 NOSQL有哪些
- 华为机试题--11.句子逆序
- Oracle 隐式转换
- Tomcat支持中文名和不区分大小写!
- 在Jenkins上用Dr Memory做内存测试
- Java - 数据库(mysql - 1)
- github上搭建博客并使用多说
- 自定义Dialog中点击EditText无法弹出软键盘的问题
- 局部变量、全局变量、堆、堆栈、静态和全局【转】
- HTML canvas 笑脸
- oracle笔记
- 解决IE10以下对象不支持“bind”属性或方法
- Mysql 数据类型
- 自定义圆角或圆形drawable
- C++ 多态
- Java属性Properties文件读取工具类
- 浅析React之通信机制(一)
- temporary mail file: No such file or directory