ThrBiTree(ThrBiNode* bt,ThrBiNode* &pre),bt指向当前结点,pre指向bt的前一个结点,pre本身就是指针变量要加个引用是为了修改他,那bt也是要修改的啊为什么不加引用?
具体实现如下:
struct ThrBiNode{//结构体定义
char data;
ThrBiNode *lchild,*rchild;
int ltag,rtag;
} * pre;
void InThrBiTree::ThrBiTree(ThrBiNode* bt,ThrBiNode* &pre){//线索化
if(bt!=NULL){
ThrBiTree(bt->lchild,pre);
if(bt->lchild==NULL){//处理左边
bt->lchild=pre;
bt->ltag=1;
}
if(bt->rchild==NULL){//处理右边
bt->rtag=1;
}
if(pre&&pre->rtag){//处理前驱的后继
pre->rchild=bt;
}
pre=bt;//指针后移
ThrBiTree(bt->rchild,pre);
}
}