std :: map按数据排序? [英] std::map sort by data?

查看:432
本文介绍了std :: map按数据排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过数据而不是键对std :: map进行排序?现在,我的代码只是将整个地图复制到一个数组中.

解决方案

据我所记得,std::map将为您提供迭代器,该迭代器将处理按键排序的项目.只能通过值来遍历按值对已排序项进行排序并仍然使用该映射的唯一方法是,将整个集合重写为另一个映射,并反转键和值.

Is there a way to sort std::map by the data rather than the key? Right now my code duplicates the entire map in to an array just to do this.

解决方案

As far as I can remember, std::map will give you the iterator that will go through the items sorted by the key. Only way to go through the sorted items by the value, and still use the map, is to rewrite whole collection to another map, with key and value reversed.

这篇关于std :: map按数据排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆