C++ 红黑树删除功能
删除功能不起作用。如果删除一个节点,剩下的就是该节点的子树 你认为这有什么不对? 提前谢谢C++ 红黑树删除功能,c++,red-black-tree,C++,Red Black Tree,删除功能不起作用。如果删除一个节点,剩下的就是该节点的子树 你认为这有什么不对? 提前谢谢 node *deleteNode(node* &root, node *z){ node *x, *y; cout << "Element to delete: " << z->data << endl; if (z->leftchild == nil || z->rightchild == nil)
node *deleteNode(node* &root, node *z){
node *x, *y;
cout << "Element to delete: " << z->data << endl;
if (z->leftchild == nil || z->rightchild == nil)
y = z;
else
y = treesuccessor(z);
if (y->leftchild != nil)
x = y->leftchild;
else
x = y->rightchild;
if (x != nil)
x->parent = y->parent;
if (y->parent == nil)
root = x;
else if (y == y->parent->leftchild)
y->parent->leftchild = x;
else
y->parent->rightchild = x;
if (y != z)
z->data = y->data;
if (y->color == black)
deletefixup(root, x);
return y;
}
node*deleteNode(node*&根,node*z){
节点*x,*y;
cout rightchild==nil)
y=z;
其他的
y=树接受器(z);
如果(y->leftchild!=nil)
x=y->leftchild;
其他的
x=y->rightchild;
如果(x!=nil)
x->parent=y->parent;
如果(y->parent==nil)
根=x;
else if(y==y->parent->leftchild)
y->parent->leftchild=x;
其他的
y->parent->rightchild=x;
如果(y!=z)
z->data=y->data;
如果(y->颜色==黑色)
deletefixup(根,x);
返回y;
}
您应该用您正在使用的语言标记问题。我不认为red-black-tree
是一个流行的标签,而c
则是。看起来像是《算法概论》中正确的抄本。:-)问题一定在别的地方。。。