问答题 设二叉树以二叉链表为存储结构,编写一个后序遍历二叉树的非递归算法(要求先用文字写出实现的基本思想,再用C语言写出算法)。【中国海洋大学2006八(15分)】
【正确答案】正确答案:void postorder(BiTree t) {typedef struct node {BiTree t; int tag;)stack;//tag 0..1 stack s[n+1]; top=0; while(t!=null || top!=0) {while(t!=null) {S[++top].t=t; S[top].tag=0;t=t一>ichild;}//进栈,向左 while(top!=0&&s[top].tag==1)//左右子女均已访问,访问根结点 cout<data; if(top){s[top].tag=1;t=s[top].t一>rchild;)//转右分支 } }//postorder
【答案解析】