std::map sort by data?

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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.

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!