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

标签 c++ data-structures heap

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

这可以用堆来实现吗?

谢谢!

最佳答案

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/

相关文章:

python - 在 python 中,我应该如何在元组列表上实现最小堆?

java - 为什么 z 没有在最小堆中冒泡?

c++ - C++11 中的无锁多生产者/消费者队列

c++ - C++中纯虚函数的用途是什么?

c++ - 如何获得所有模型或所有凸评估?

javascript - 在 Typescript 中将数组转换为树

c - 使用堆栈的数组实现

python - 当我释放由 CFFI 生成的 DLL 分配的 char* 时,为什么我的应用程序会崩溃?

java - 如何获取链表中的Node组件?

c++ - 在三元堆中实现滴流操作的最有效方法