高手们,我想建一棵树,我已经按书的算法做了,可不知道哪里错了,都困扰我N天了,各位能帮忙看看吗,在下万分感激!!!!
/* Note:Your choice is C IDE */
#include “stdio.h”
struct l
{char e;
struct l *lchild,*rchild;
}l;
main()
{struct l *p=NULL;
void buildtree(struct l *t);
p=p->lchild=p->rchild=(struct l*)malloc(sizeof(struct l));
buildtree(p);
printf(“%c”,p->lchild->e);
}
void buildtree(struct l *t)
{char ch;
scanf(“%c”,&ch);
t=(struct l*)malloc(sizeof(struct l));
if(ch==’#')t=NULL;
else{
t->e=ch;
buildtree(t->lchild);
buildtree(t->rchild);
}
}