修复红黑树内部的一个导致丢失节点的bug

This commit is contained in:
2024-09-06 20:12:20 +08:00
parent acce44863f
commit 20c1b81121
2 changed files with 36 additions and 4 deletions

View File

@@ -101,7 +101,7 @@ namespace ling {
* lx rx rx ry
*
*/
void rightRotate(Node *root, Node *y);
void rightRotate(Node *&root, Node *y);
/// 查找元素
Node *iterativeSearch(Node *x, T key) const;
@@ -438,7 +438,7 @@ namespace ling {
}
template<typename T>
void RedBlackTree<T>::rightRotate(RedBlackTree::Node *root, RedBlackTree::Node *y) {
void RedBlackTree<T>::rightRotate(RedBlackTree::Node *&root, RedBlackTree::Node *y) {
// 设置x是当前节点的左孩子。
Node *x = y->left;