使用STL中的stable_sort()函数进行排序
来源:互联网 发布:seo是干嘛的 编辑:程序博客网 时间:2024/06/03 15:56
#include<iostream>#include<vector>#include<algorithm>#include<iterator>using namespace std;typedef struct TagNode{ int value; int index;}Node; //TagNode结构体的别名Node bool myCmp(const Node& a,const Node& b) //声明两个引用a,b{ return a.value<b.value;}int main(int argc,char **argv) //argc是命令行总的参数个数,argv是argc个参数{ vector<Node>coll; //创建存储Node类型值的容器coll Node tmp; int num,idx = 0; while(cin >> num && num) {++idx;tmp.value = num;tmp.index = idx;coll.push_back(tmp); } stable_sort(coll.begin(),coll.end(),myCmp); cout << "Index\tValue:" << endl; vector<Node>::iterator pos; for(pos = coll.begin();pos != coll.end();++pos) {cout << pos->index << "\t" << pos->value << endl; } return 0;}
输入0结束输入数字
当遇到值相同的时候,索引号较小的排在前面:)
- 使用STL中的stable_sort()函数进行排序
- STL stable_sort 稳定排序
- STL中的排序算法 sort stable_sort patition_sort等
- STL中的排序算法 sort stable_sort patition_sort等
- STL中的排序算法 sort stable_sort patition_sort等
- STL中的排序算法 sort stable_sort patition_sort等
- 实战c++中的vector系列--使用sort算法对vector进行排序(对vector<string>排序、使用稳定的排序std::stable_sort())
- 【STL】stable_sort !!!
- c、c++排序函数qsort、stable_sort
- C++使用STL进行排序
- STL 之 stable_sort 将牌从大到小排序
- stable_sort使用
- 使用sort()函数对数组中的数字进行排序。
- 在STL泛型算法中的排序函数sort内部使用的是哪种排序算法呢?
- STL中的排序函数(模板)
- HDOJ 1106 排序 [stable_sort]
- 【stable_sort稳定排序】
- stable_sort稳定排序
- Unity之串口通信(基于三姿态传感器)
- TOADxiaiza
- ubuntu12.04 安装星际译王
- DebianLNMP虚拟主机管理工具Nginx PHP5.3 MySQL管理软件
- web project 配置文件
- 使用STL中的stable_sort()函数进行排序
- DebianLNMP虚拟主机管理工具Nginx PHP5.3 MySQL管理软件
- VS2010环境下Boost 1.49.0配置笔记
- アジャイルの流儀で英語に挑戦!
- 学科前沿技术(图灵奖,其近两年来的获得者)
- 导入项目时发生的问题
- 最新计算机世界排名
- SCP 和 SFTP 的区别
- os.path----平台独立的文件名管理