sort algorithm
来源:互联网 发布:java 获取apk版本号 编辑:程序博客网 时间:2024/06/05 11:53
MSDN中的定义:
1.template<class RanIt> void sort(RanIt first, RanIt last);
2.template<class RanIt, class Pred> void sort(RanIt first, RanIt last, Pred pr);
头文件:
#include <algorithm>
using namespace std;
1.默认的sort函数是按升序排。对应于1
sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址
2.可以自己写一个cmp函数,按特定意图进行排序。对应于2
例如:是对数组a降序排序
int cmp( const int &a, const int &b )
{
if( a > b )
return 1;
else
return 0;
}
sort(a,a+n,cmp);
又如:
是先按x升序排序,若x值相等则按y升序排
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);
0 0
- sort algorithm
- sort algorithm
- Sort algorithm
- Sort Algorithm-->Bubble Sort
- Sort Algorithm-->Select Sort
- Sort algorithm overview.
- quick sort algorithm
- insert sort algorithm
- select sort algorithm
- Insertion sort algorithm
- Algorithm---Selection Sort
- Algorithm---Insert Sort
- ACM algorithm sort
- STL: <algorithm>中 sort()
- Csharp Algorithm - Bubble Sort
- CSharp Algorithm - Shell sort
- Select Sort Algorithm
- Sort Algorithm 总结
- [转]阅读源码的感悟
- [转]关于敏捷开发的26个心得
- 第2次实验——算法基本功
- Ubuntu程序自启动
- poj1947 Rebuilding Roads 树形dp
- sort algorithm
- 数据结构课程设计--广义表(链式实现)
- 堆和栈的区别 (转贴)
- 浅谈协方差矩阵
- 开源SVM库libSVM介绍
- poj-3295 Tautology
- C语言综合研究与高强度程序设计训练 2
- Hash Join
- LA 5095 Transportation 费用流