帮忙看下这个2叉树的建立
#include"stdio.h"typedef struct a{
char b;
struct a *l,*r;
}c;
void maketree(c *q);
void zhongxu(c *q);
main()
{
c *h;
maketree(h);
zhongxu(h);
return 0;
}
void maketree(c *q) /*中序输入*/
{
c *p;
char x;
p=(c *)malloc(sizeof(c));
q=p;
printf("plesase enter the data\n");
p->b=getche(); /*输入节点的数据域*/
printf("if you don't want to the left plesase enter the '#'\n");
x=getche();
if(x!='#') /*判断有没左孩子*/
maketree(p->l);
else
p->l=NULL;
printf("if you don't want to the right plesase enter the '#'\n");
x=getche();
if(x!='#') /*判断有没右孩子*/
maketree(p->r);
else
p->r=NULL;
}
void zhongxu(c *q) /*中序输出*/
{
if(q!=NULL)
{
printf("%c",q->b);
zhongxu(q->l);
zhongxu(q->r);
}
}
代码问题是输不出结果来,但本人感觉在建立2叉树上逻辑上是正确的
先谢了