while(p || !s.empty())
{
if(p)
{
s.push(p);
p = p->leftChild;
}
else
{
p = s.top();
p->Visit();
s.pop();
p = p->rightChild;
}
}
}
void BiTree::Destroy(Node * &root)
{
if(root)
{
Destroy(root->leftChild);
Destroy(root->rightChild);
delete root;
root = NULL; //这一步为规范操作,防止root成为野指针
}
}
BiTree::~BiTree()
{
Destroy(root);
}
相关阅读: