STL sort用法
来源:互联网 发布:java程序设计案例教程 编辑:程序博客网 时间:2024/06/10 07:00
sort函数有两个参数和三个参数的,两个参数的简单些只需起始iterator和终止iterator。
下面用一个例子说明三个参数的sort函数的用法:
如:
34 234
324 213
46 2
6 35
46 5
对第一列进行排序,第二列对应原先的数值保持不变,排序后:
6 35
34 234
46 2
46 5
324 213
程序代码:
#include <iostream>#include <vector>#include <algorithm>using namespace std;typedef struct tagTwoNum{ int x; int y;}TWO_NUM;bool my_fun(TWO_NUM t1, TWO_NUM t2){ return (t1.x < t2.x);}int main(void){ TWO_NUM temp[] = {34, 234, 324, 213, 46, 2, 6, 35, 46, 5}; vector<TWO_NUM> vt(temp, temp+5); vector<TWO_NUM>::iterator iter; sort(vt.begin(), vt.end(), my_fun); for (iter=vt.begin(); iter!=vt.end(); ++iter) { cout << (*iter).x << "\t" << (*iter).y << endl; } return 0;}
- STL sort用法
- STL:Sort用法
- STL sort用法
- STL的sort用法
- STL:sort()用法
- 【STL】sort函数的用法
- STL中sort函数用法
- STL sort函数的用法
- STL sort函数的用法
- STL 中sort、qsort 的用法
- STL中sort的用法举例
- stl里list的sort()用法
- STL中sort的用法举例
- STL 中sort、qsort 的用法
- 【STL】sort和copy的用法
- STL 中 sort 函数用法简介
- STL sort原理及用法详解
- STL 中 sort 函数用法简介
- 05 守护进程的出错处理
- 第二章 项目管理模型
- 软件开发工期估算系列(7)——規模見積もりの女王様「FP見積もり」【後編】(内附FP简易算法示例)
- 记录socket函数调用分析
- XML 根级别上的数据无效。 行 1,位置 1
- STL sort用法
- 【動態規劃】飆車
- struts2 Action中获取request, response,Session对象的方法
- POJ1887 Testing the CATCHER 最大下降子序列 DP
- asp.net成员资格与角色管理使用和配置
- com,ole,atl,activex的区别和联系
- ActiveX,OLE,COM之间的关系
- ASCII码表 上传博客收藏下
- 高效编写Java代码的几条建议