求找错 线索二叉树输出结果总是不对
#include<iostream>using namespace std;
typedef char elemtype;
typedef struct BiThrNode{
elemtype data;
BiThrNode *lchild,*rchild;
int RTag,LTag;
BiThrNode()
{data=NULL;
lchild=NULL;
rchild=NULL;
}
}*BiThrTree;
BiThrTree Creat()
{BiThrNode*T;
char i;
static int flag=1;
T=new BiThrNode;
if(flag==1)
cout<<"请输入根结点的data值(以#表示结束):";
else cout<<"请输入结点的data值:";
cin>>i;
flag++;
if(i=='#')T=NULL;
else
{ T->data=i;
T->lchild=Creat();
T->rchild=Creat();
}
return T;
}
BiThrTree pre,p;
void InThreading(BiThrTree p)
{ if(p)
{ InThreading(p->lchild);
if(!p->lchild){p->LTag=1;p->lchild=pre;}
if(!pre->rchild){pre->RTag=1;pre->rchild=p;}
pre=p;
InThreading(p->rchild);
}
}
BiThrTree InOrderThreading(BiThrTree T) //中序线索化二叉树
{BiThrTree Thrt;
Thrt=new BiThrNode;
Thrt->LTag=0;
Thrt->RTag=1;
Thrt->rchild=Thrt;
if(!T)Thrt->lchild=Thrt;
else{
Thrt->lchild=T;
pre=Thrt;
InThreading(T);
pre->RTag=1;
pre->rchild=Thrt;
Thrt->rchild=pre;
}
return Thrt;
}
void InorderTraverseprint(BiThrTree Thrt)//中序遍历输出线索二叉树
{ BiThrTree p;
p=Thrt->lchild;
while(p!=Thrt)
{while(p->LTag==0)
p=p->lchild;
cout<<p->data<<"\t";
while(p->RTag==1&&p->rchild!=Thrt)
{
p=p->rchild;
cout<<p->data<<"\t";}
}
p=p->rchild;
}
int main()
{BiThrTree t1,t2;
t1=Creat();
t2=InOrderThreading(t1) ;
InorderTraverseprint(t2);
return 0;
}
输出结果总是不对 求高人指点啊