该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
struct shu
{
char shuju;
struct shu *left;
struct shu *right;
}*p;
struct shu* tree(struct shu *p)
{ char a;
scanf("%c",&a);
getchar();
if(a==' ')
{
p=NULL; /*a为空格的时候,说明此结点为空*/
}
else
{ /*否则申请空间,并赋值*/
while((p=(struct shu*)malloc(sizeof(struct shu)))==NULL);
p->shuju=a;
tree(p->left);
tree(p->right);
}
return p;
}
/*void bianli(struct shu *q)
{
if(q)
{
printf("%c ",q->shuju);
bianli(q->left);
bianli(q->right);
}
}*/
int main()
{ struct shu *T=NULL,*q=NULL;
T=tree(q);
printf("%c",T->shuju);
T=T->left;
printf("%c",T->shuju);
/* bianli(T);*/
return 0;
}
遍历的函数大家不用看了,就帮我看看,为什么返回的T只能打印头结点的值。