gpt4 book ai didi

c++ - 插入多重集 : before the first occurence of that value instead of after the last occurence

转载 作者:搜寻专家 更新时间:2023-10-30 23:51:13 26 4
gpt4 key购买 nike

正如标题所说,multiset 在所有相同值的范围末尾插入一个值。

(例如:在多重集 1,2,2,3 中插入 2 使其成为 1,2,2,/*new*/2,3)。

如何在所有相同值范围的开头插入新值?

(例如:在多重集 1,2,2,3 中插入 2 应该使 1,/*new*/2,2,2,3)

最佳答案

试试这个

std::multiset<int> mset { 2,4,5,5,6,6 }; 
int val = 5;
auto it = mset.equal_range ( val ).first; //Find the first occurrence of your target value. Function will return an iterator

mset.insert ( it, val ); //insert the value using the iterator

关于c++ - 插入多重集 : before the first occurence of that value instead of after the last occurence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57270605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com