我有一个二叉搜索树,当我尝试删除具有单个子节点的节点时,删除该节点并将子节点移动到它的位置。我有它的代码,但是每当我这样做时,它都会给我一个错误的指针。
这是代码段
else if((root->Left != NULL) != (root->Right != NULL)){ //Checks if it's a on child node
if(root->Left != NULL){ //If it has a left child, attempts to move the left child to existing node
delete root;
root = root->Left;
}
else{ //If it is right child, attempts to move right child to existing node
delete root;
root = root->Right;
}
}
该结构具有值
DATA_TYPE Value;
TreeNode* Left;
TreeNode* Right;
我知道我从调试器中分配错误,那么移动节点的正确方法是什么?