建议任何方法来对键及其值的多重映射进行排序。例如- 输入- (5,1), (1,9), (1,1), (5,2), (1,2) 输出必须是- (1,1)、(1,2)、(1,9)、(5,1)、(5,2)。
最佳答案
答案是 emplace_hint。伪代码看起来像这样:-
insert_with_hint(M mmap, K key, V Value)
{
auto i1 = mmap.equal_range(Key);
for (auto i2 = i1.first; i2 != i1.second; ++i2)
{
if (i2->second > Key) { // <-- Here add your sorting criteria
mmap.emplace_hint(i2,Key,Value)
return
}
}
mmap.emplace(Key,Value)
}
关于c++ - 如何对多映射中的键和值进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21215214/