提供红黑树的移动构造和移动赋值函数,并删除拷贝构造以及拷贝赋值

This commit is contained in:
2024-09-07 14:23:19 +08:00
parent 20c1b81121
commit 578515d65f

View File

@@ -118,6 +118,24 @@ namespace ling {
public:
explicit RedBlackTree() = default;
RedBlackTree(const RedBlackTree &other) = delete;
RedBlackTree(RedBlackTree &&other) noexcept {
this->rootNode = other.rootNode;
other.rootNode = nullptr;
}
RedBlackTree &operator=(RedBlackTree &&other) noexcept {
if (this == &other) {
return *this;
}
this->rootNode = other.rootNode;
other.rootNode = nullptr;
return *this;
}
RedBlackTree &operator=(const RedBlackTree &other) = delete;
virtual ~RedBlackTree() {
destroy();
}