c语言实现二叉树线索化问题

Cocoo光 发布于 2016/05/14 18:11
阅读 71
收藏 0
这是我写的程序,InPostNode函数有问题,求大神指点,编译出错为

5012D:\QQPCmgr\Desktop\课程设计14.c[Error] conflicting types for 'InPostNode'


#include"stdio.h"
#include"malloc.h"
typedef char DataType;
typedef struct Threadnode{
int ltag,rtag;
DataType data;
struct Threadnode *lchild,*rchild;
}Threadnode,*ThreadTree;
int creat_BTree(ThreadTree *t){
char ch;
scanf("%c",&ch);
if(ch=='#') *t=NULL;
else{
*t=(ThreadTree)malloc(sizeof(Threadnode));
if(!(*t))
return 0;
(*t)->data=ch;
creat_BTree(&(*t)->lchild);
creat_BTree(&(*t)->rchild); 
}
return 1; 
}
void InThread(ThreadTree t,ThreadTree pre){
if(t){
InThread(t->lchild,pre);
if(t->lchild==NULL){
t->ltag=1;
t->lchild=pre;
}
if(t->rchild==NULL)
t->rtag=1;
if((pre)&&(pre->rtag==1))
pre->rchild=t;
pre=t;
InThread(t->rchild,pre);
}
}
void InOrderTh(ThreadTree t){
ThreadTree p;
if(t){
p=t;
while(p->ltag==0)
p=p->lchild;
while(p){
printf("%c",p->data);
p=InPostNode(p);
}
}
}
ThreadTree InPostNode(ThreadTree p){
ThreadTree post;
post=p->lchild;
if(p->rtag==1)
return post;
else
while(post->ltag==0)
post=post->lchild;
return post;
}
main(){
ThreadTree t,pre;
creat_BTree(&t);
InThread(t,pre);
InOrderTh(t);
}

加载中
返回顶部
顶部