void PostTraversal(BTNode *root)
{
BTNode *cur = NULL;
BTNode *pre = NULL;
stack<BTNode *> s;
s.Push(root);
while(!s.IsEmpty())
{
cur = s.GetTop();
if((cur->lchild == NULL && cur->rchild == NULL) || (pre != NULL && (pre == cur->lchild || pre == cur->rchild)))
{
printf("%c",cur->data);
pre = s.Pop();
}
else
{
if(cur->rchild != NULL)
{
s.Push(cur->rchild);
}
if(cur->lchild != NULL)
{
s.Push(cur->lchild);
}
}
}
}
【二叉树】后续遍历二叉树
最新推荐文章于 2022-04-17 19:23:17 发布