求教各位大佬,为什么输出一直不对呢 struct tempnode { Treenode *root; int flag; }; tempnode *a = new tempnode;
void posoderfeidigui(Treenode *root) { stack<tempnode*> s;
while (root != NULL || (!s.empty()))
{
//一直将左子树压栈
while (root != NULL)
{
a->root = root;
a->flag = 1;
s.push(a);
root = root->lchild;
}
//左子树处理完成后,弹出最下面的左子树,并返回上方左子树
while ((!s.empty()) && s.top()->flag == 2)
{
root = s.top()->root;
s.pop();
cout << root->ch;
}
if ((!s.empty()))
{
s.top()->flag = 2;
root = s.top()->root->rchild;
}
}
}