gpt4 book ai didi

c++ - 哪个数据结构在附加重复项时提供替换操作?

转载 作者:行者123 更新时间:2023-11-28 00:43:12 24 4
gpt4 key购买 nike

是否有一种数据结构可以以低复杂度消除重复项?添加新值时,不应在已有相同值时添加。

这可以用堆来实现吗?

谢谢!

最佳答案

std::set 这样做。事实上,如果您不想发生这种情况,您需要切换到多重集。

来自documentation的集合

Because elements in a set are unique, the insertion operation checks whether each inserted element is equivalent to an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element (if the function returns a value).

关于c++ - 哪个数据结构在附加重复项时提供替换操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17763162/

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