Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 红黑树删除功能_C++_Red Black Tree - Fatal编程技术网

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
则是。看起来像是《算法概论》中正确的抄本。:-)问题一定在别的地方。。。