请教关于建立二叉树程序(c语言的)

来源:百度知道 编辑:UC知道 时间:2024/06/07 08:47:25
#include<stdio.h>
#include<malloc.h>
typedef struct
{
char data;
struct node *lchild,*rchild;
}Tree;

void Init(Tree *t)
{
char ch;
printf("input a char:\n");
scanf("%c",&ch);

if(ch=='#')t=NULL;
if(ch=='%')return;
else
{
t=(Tree*)malloc(sizeof(Tree));
t->data=ch;
Init(t->lchild);
Init(t->rchild);
}
}

void Xbl(Tree *t)
{
while(t)
{
printf("%c",t->data);
Xbl(t->lchild);
Xbl(t->rchild);
}
}

main()
{
Tree t;
Init(&t);
Xbl(&t);
getch();
}
老是死循环,哪里有问题,请帮忙改一下

dsd.cpp
C:\Documents and Settings\Administrator\桌面\dsd.cpp(21) : error C2664: 'Init' : cannot convert parameter 1 from 'struct node *' to 'Tree *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\dsd.cpp(22) : error C2664: 'Init' : cannot convert parameter 1 from 'struct node *' to 'Tree *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\dsd.cpp(31) : error C2664: 'Xbl' : cannot convert parameter 1 from 'struct node *' to 'Tree *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\dsd.cpp(32) : err