请帮忙。我的删除功能有什么问题。似乎无法弄清楚
我似乎遇到了错误: 类声明似乎很好。主要问题是让这个删除功能起作用
void binaryTree::Remove(int) {
if (node != NULL)
{
Node* tmptr = node;
int rootdata = node->data;
/int rSubtree;
}
{
// Case 0- no child
if (node->lChild == NULL && node->rChild == NULL)
{
node = NULL;
//parent- //set the parent of the node to NULL
delete node;
}
// has one child
else if (node->lChild == NULL && node->rChild != NULL)
{
node = node->rChild;
node->rChild = NULL;
delete node;
}
else if (node->lChild != NULL && node->rChild == NULL)
{
node = node->lChild;`enter code here`
node->lChild = NULL;
delete node;
}
}
答案 0 :(得分:1)
尝试使用node = NULL
交换delete node;
,否则您将尝试删除NULL。