#include
typedef char Elemtype;
typedef struct TbNode{
TbNode *Lchild,*Rchild;
int Ltag,Rtag;
}TBTNode;
TBTNode *root=0;
TBTNode *prev;
void insert(Elemtype el){
TBTNode *pre=0,*p=root,*newNode;
newNode=new TBTNode;
newNode->info=el;
newNode->Lchild=0;
newNode->Rchild=0;
if(root==0){
root=newNode;
return;
while(p!=0){
pre=p;
if(elinfo)
p=p->Lchild;
else
p=p->Rchild;
}
if(elinfo)
pre->Lchild=newNode;
else
pre->Rchild=newNode;
}
void creaTBTNode(TBTNode * &b,Elemtype *str){
char ch;
int j=0;
while(ch!='\0'){
//printf("%c\n",ch);
if(ch!=',')
ch=str[j];
}
}
void showtree(TBTNode *b){
if(b!=0){
printf("%c",b->info);
if(b->Lchild!=0||b->Rchild!=0){
printf("(");
showtree(b->Lchild);
if(b->Rchild!=0)
showtree(b->Rchild);
printf(")");
}
}
}
void threat(TBTNode * &p){
threat(p->Lchild);
if(p->Lchild==0){
p->Lchild=prev;
p->Ltag=1;
}
else
p->Ltag=0;
if(prev->Rchild==0){
prev->Rchild=p;
prev->Rtag=1;
}
else
prev->Rtag=0;
prev=p;
threat(p->Rchild);
}
}
TBTNode *creaThreat(TBTNode * b){
TBTNode *newroot;
newroot=new TBTNode;
newroot->Lchild=b;
newroot->Ltag=0;
newroot->Rtag=1;
if(b==0)
else{
newroot->Lchild=b;
prev=newroot;
threat(b);
prev->Rchild=newroot;
prev->Rtag=1;
newroot->Rchild=prev;
}
return newroot;
}
void THinorder(TBTNode *tb){
TBTNode *p=tb->Lchild;
while(p!=tb){
while(p->Ltag==0)
p=p->Lchild;
printf("%c ",p->info);
while(p->Rtag==1&&p->Rchild!=tb){
printf("%c ",p->info);
}
p=p->Rchild;
}
}
int main(){
TBTNode *b,*st;
creaTBTNode(b,"B,A,C,H,J,L,F,U,O,Y,T,I");
showtree(b);
THinorder(st);
return 0;
}