线索二叉树输出为空????
结构体
typedef struct Node
{
ElementType data;
int Ltag;
int Rtag;
struct Node *LChild;
struct Node *RChild;
}BiTNode,*BiTree;
查找后继
BiTNode *InNext(BiTNode *p)
{
BiTNode *next;
BiTNode *q;
if(p->Rtag==1)
next=p->RChild;
else
{
if(p->RChild!=NULL)
{
for(q=p->RChild;q->Ltag==0;q=q->LChild);//查找最左下端节点
next=q;
}
else
next=NULL;
}
return(next);
}
打印输出
BiTNode *TinFirst(BiTree Root)
{
BiTNode *p;
p=Root;
if(!p) return NULL;
while(p->Ltag==0)
p=p->LChild;
return p;
}
void TinOrder(BiTree Root)
{
BiTNode *p;
p=TinFirst(Root);
while(p)
{
printf("%d %c %d",p->Ltag,p->data,p->Rtag);
p=InNext(p);
}
}
怎么只是输出一个 ,别的都不输出 如下:
0 D 0
还有这里
查找前驱节点
BiTNode *InPre(BiTNode *p)
{
BiTree pre;
pre=(BiTree)malloc(sizeof(BiTNode));
BiTNode *q;
if(p->Ltag==1)
pre=p->LChild;//
else
{
for(q=p->LChild;q->Rtag==0;q=q->RChild);//查找最右下端节点
pre=q;
}
return pre;
}
查找前驱节点的时候,内存不能为read 如果改成for(q=p->LChild;q->Rtag=0;q=q->RChild);则能找到
主要是这里的q->Rtag=0和==0,怎么错了
而书上是吧pre定义成了全局变量,我写在InPre里就出这样的错误
[解决办法]
q->Rtag=0 always return ture