c++如何按照map的value进行排序?
2021-02-05 06:14
标签:i++ return etc col style map order pre sort 答:将map中的pair装入到vector中,再自定义sort的cmp函数(参考leetcode451) c++如何按照map的value进行排序? 标签:i++ return etc col style map order pre sort 原文地址:https://www.cnblogs.com/qiezi-online/p/12790423.html static bool cmp(pairchar, int> a , pairchar,int> b)
{
return a.second>b.second; //按照value从大到小重新排序
}
string frequencySort(string s) {
unordered_mapchar,int> m;
for(auto i:s)
m[i]++;
vector
文章标题:c++如何按照map的value进行排序?
文章链接:http://soscw.com/index.php/essay/51199.html