为什么要删除自己还要判断父亲是否为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;
}
慕粉1600176492
__innocence
随时随地看视频慕课网APP