删除功能不起作用。如果删除节点,剩下的就是节点的子树。
你认为这有什么问题? 提前谢谢。
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;
}