您的位置:首页 > 其它

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升序排
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: