//树的线索化中序
#include<iostream>
using namespace std;
typedef struct BiThrNode{
char data;
struct BiThrNode *lchild,*rchlild;
int LTag,RTag;
}BiThrNode,*BiThrTree;
BiThrNode *pre = new BiThrNode;
void CreateBiTree(BiThrNode &T){
char ch;
cin>>ch;
if(ch=='#') T=NULL;
else{
T=new BiThrNode;
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchlild);
}
}
void InThreading(BiThrTree p){
if(p){
InThreading(p->lchild);
if(!p->lchild){
p->LTag=1;
p->lchild=pre;
}else{
p->LTag;
}
if(!pre->rchlild){
pre->RTag=1;
pre->rchlild=p;
}else{
pre->RTag=0;
}
pre=p;
InThreading(p->rchlild);
}
}
void main(){
pre->RTag=1;
pre->rchlild=NULL;
BiThrTree tree;
cout<<"please input:\n";
CreateBiTree(tree);
InThreading(tree);
cout<<"finish!\n";
}
原文:https://www.cnblogs.com/ygjzs/p/11874604.html