sort的用法
来源:互联网 发布:释放被占用的端口 编辑:程序博客网 时间:2024/06/05 05:11
sort的用法:详细见cplusplus。
1.默认的sort函数是按升序排。对应于1)
sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址
2.可以自己写一个cmp函数,按特定意图进行排序。对应于2)
例如:
1.默认的sort函数是按升序排。对应于1)
sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址
2.可以自己写一个cmp函数,按特定意图进行排序。对应于2)
例如:
// sort algorithm example#include <iostream> // std::cout#include <algorithm> // std::sort#include <vector> // std::vectorbool myfunction (int i,int j) { return (i<j); } //升序排列struct myclass { bool operator() (int i,int j) { return (i>j);}//降序排列} myobject;int main () { int myints[] = {32,71,12,45,26,80,53,33}; std::vector<int> myvector (myints, myints+8); // 32 71 12 45 26 80 53 33 // using default comparison (operator <): std::sort (myvector.begin(), myvector.begin()+4); //(12 32 45 71)26 80 53 33 // using function as comp std::sort (myvector.begin()+4, myvector.end(), myfunction); // 12 32 45 71(26 33 53 80) // using object as comp std::sort (myvector.begin(), myvector.end(), myobject); //(12 26 32 33 45 53 71 80) // print out content: std::cout << "myvector contains:"; for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
- 【笔记】 sort的用法
- SORT的详细用法
- sort 的用法详解
- sort 命令的用法
- Arrays.sort()的用法
- sort函数的用法
- *sort的一些用法*
- sort的高深用法
- sort的用法
- sort的用法
- sort函数的用法
- STL的sort用法
- Sort函数的用法
- sort函数的用法
- sort的用法
- linux sort的用法
- sort函数的用法
- sort函数的用法
- 用div+css制作圆角矩形的原理
- 如何让你的进程更加“强硬”
- SQL 查询数据
- easyui与ssh(struts1)的整合实现增删改查、分页
- Compilation problem with oprofile regarding libbfd
- sort的用法
- 插件框架实现思路及原理
- Spring配置:用context:property-placeholder替换PropertyPlaceholderConfigurer
- SQL 函数与分组查询数据
- 多表连接查询与子查询
- Android上的内存分配策略优化
- hdu3652
- Android Paint和Color类
- 插入删除数据