博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
map按照value排序的方法
阅读量:7121 次
发布时间:2019-06-28

本文共 788 字,大约阅读时间需要 2 分钟。

1.将map以pair(string,double)的存储方式加入vector中

2.vector的sort()中的第三个参数重载

#typedef pair<string,double>  PAIR

struct CmpByValue {
bool operator()(const PAIR& lhs, const PAIR& rhs) {
return lhs.second < rhs.second;
}
};

 

    map
name_score_map;
name_score_map["LiMin"] = 90;
name_score_map["ZiLinMi"] = 79;
name_score_map["BoB"] = 92;
name_score_map.insert(make_pair("Bing",99));
name_score_map.insert(make_pair("Albert",86));
//把map中元素转存到vector中
 
vector
name_score_vec(name_score_map.begin(), name_score_map.end());
sort(name_score_vec.begin(), name_score_vec.end(), CmpByValue());
// sort(name_score_vec.begin(), name_score_vec.end(), cmp_by_value);
 
for (int i = 0; i != name_score_vec.size(); ++i) {
 
qDebug()<
}
qDebug()<

转载于:https://www.cnblogs.com/Pymcj/p/6678650.html

你可能感兴趣的文章
2018云栖大会深圳峰会-企业级互联网架构专场看点提前大放送!
查看>>
邱剑 | 美团云容器实践之路
查看>>
C#连接Oracle错误:OCIEnvCreate 失败,返回代码为 -1
查看>>
【干货合集】让我们聊一聊如何用世界上最流行的脚本语言——JavaScript写出优美的代码...
查看>>
.net 发送电子邮件
查看>>
阿里云API应用创新大赛总决赛,强者之争即将开启
查看>>
windows 系统监视器 以及建议阀值
查看>>
广州证券携手8Manage 实现数字化管理体验
查看>>
bootstrap-表单控件——按钮
查看>>
[数据结构]约瑟夫环问题
查看>>
Spring系列之AOP分析之获取Advice的过程(四)
查看>>
CSS之浮动那些事
查看>>
BPM实例方案分享:表单子表自动填入数据
查看>>
进程 线程
查看>>
iproute(网卡限速)--使用方法
查看>>
开源项目spring-shiro-training思维导图
查看>>
Memcache 查看列出所有key的方法
查看>>
DataBinding初识
查看>>
CentOS Docker 安装
查看>>
python set(集合)
查看>>