在c++中实现一个set模板的添加和删除
Implementing a set template in c++ adding and removing
我需要为SET数据结构创建一个添加和删除函数,而不使用c++的STL。这里是。h代码,我需要写出代码来实现。h代码中的函数。这是一个模板化类,用于将其属性继承到更大范围的项目中。虽然我知道没有太多的事情要做,但我真的很感激你的帮助,因为这是我简单给出的所有指示。
template <class T>
class Set {
public:
Set();
Set(const Set<T> & other); //copy constructor that makes a deep copy
~Set(); //destructor
void add (const T & item); //Adds the item to the set
void remove (const T & item); //Removes the item from the set
}
如果有人能告诉我正确的方向,我将非常感激。
这里有一个简单的方向:看看set和map在STL中的实现。也要读一些关于二叉搜索树(如果你需要实现和std::set
一样复杂的东西),尤其是红黑树的知识。另一种选择是使用散列映射。
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 如何在C++中从两个单独的for循环中添加两个数组
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 如何仅为一个函数添加延迟
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 如何将更多文件夹添加到c++include路径
- 如何将元素添加到数组的线程安全函数?
- QT通过C++添加映射QML项目
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 为什么我无法更改"set<set>"循环中的值<int>
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 对于set上的循环-获取next元素迭代器
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 只能向C++添加一定数量的字符
- 有什么理由不扩展 std::set 以添加下标运算符吗?
- 如何将 std::set 的元素添加到另一个非空集
- 为什么我得到这个奇怪的错误时,试图添加一个重复的对象std::set
- 在c++中实现一个set模板的添加和删除