此代码存在运行时错误,我无法确定问题所在。stack 类有一个基本的栈操作(pop push top),用来保存遍历的位置。
parityBST::~parityBST()
{
if (root == NULL)
{
return;
}
else
{
//postOrder non recursive traversal for destructor
stack* s1 = new stack();
s1->push(root);
binaryNode* nodePtr= root;
while (!s1->isEmpty())
{
//RUNTIME ERROR HERE (after several iterations)
if (nodePtr->left)
{
s1->push(nodePtr->left);
nodePtr = nodePtr->left;
} else if (nodePtr->right)
{
s1->push(nodePtr->right);
nodePtr = nodePtr->right;
} else
{
delete nodePtr;
s1->pop();
nodePtr = s1->getTop();
}
}
}
}