单项选择题
试写一个算法,为一棵二叉树建立后序线索二叉树。
StatusPostOrderThreading(BiThrTree& T,BiThrTree& pre);//首先建立后序线索树
StatusFindNextInBiThrTree(BiThrTree& q,TElemType *p);//再进行查找 // 后序线索二叉树的算法
StatusPostOrderThreading(BiThrTree& Thrt,BiThrTree& T){ BiThrTree pre; Thrt=new BiThrNode; // 为线索二叉树建立头结点 if(!Thrt) exit(OVERFLOW); Thrt->LTag=Link; Thrt->RTag=Thread; Thrt->rchild=Thrt;// 右子树回指 if(!T) Thrt->lchild=Thrt;// 若二叉树空,左子树回指 else{ Thrt->lchild=T; pre=Thrt;
PostThreading(T,pre);// 后序遍历进行后序线索化
pre->rchild=Thrt;//最后一个结点线索化 pre->RTag=Thread; Thrt->rchild=pre; } return OK;}
StatusPostThreading(BiThrTree& T,BiThrTree& pre){ if(T){
if(T->LTag==Link)PostThreading(T->lchild,pre);
if(T->RTag==Link)PostThreading(T->rchild,pre); if(!T->lchild){ T->LTag=Thread; ___________ }
if(pre &&!pre->rchild){ pre->RTag=Thread; pre->rchild=T; } pre=T; } return OK;}
A.T->lchild=pre;
B.pre->lchild=T
C.T->rchild=pre
D.pre->rchild=T