红黑树删除功能

时间:2012-03-27 13:38:37

标签: 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)
            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;
}

0 个答案:

没有答案
相关问题