|
1鱼币
void PostOrderTraverse(BiTree T)//后序遍历非递归算法
{
SqStack S;
InitStack(S);
BiTree temp=T;
BiTree p;
BiTree lastvist = NULL;
p=T;
while (p||!StackEmpty(S))
{
while (p)
{
Push(S,p);
p= p->lchild;
}
GetTop(S,p);
if (p->rchild==NULL||p->rchild==lastvist)
{
printf("%c",p->data);
Pop(S,lastvist);
}
else
p = p->rchild;
}
}
Status CreateBiTree(BiTree &T)
{
char ch;
scanf("%c",&ch);
if(ch==' ')T=NULL;
else
{
if(!(T=(BiTNode *)malloc(sizeof(BiTNode))))exit(OVERFLOW);
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
return OK;
}
大家看看这代码那错了
|
|