为什么要删除自己还要判断父亲是否为NULL,自己都还没被delete掉,难道父亲会被先delete掉吗?void Node::Nodedelete()
{
if (!this->LeftChild)
{
this->LeftChild->Nodedelete();
}
if (!this->RightChild)
{
this->RightChild->Nodedelete();
}
if (!this->ParentNode)
{
if (this == this->ParentNode->LeftChild)
{
this->ParentNode->LeftChild = nullptr;
}
if (this == this->ParentNode->RightChild)
{
this->ParentNode->RightChild = nullptr;
}
}
delete this;
}
1 回答
- 1 回答
- 0 关注
- 1425 浏览
添加回答
举报
0/150
提交
取消