二叉树程序错误?
#include "stdafx.h"#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define NULL 0
typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}bitnode,*bitree;
bitree create(bitree t)//为什么一直输入字符?而不不能退出,程序该如何修改?
{
char ch;
scanf("%c",&ch);
if(ch=='#')
{
t=NULL;
}
else
{
t=(bitree)malloc(sizeof(bitnode));
t->data=ch;
t->lchild=create(t->lchild);
t->rchild=create(t->rchild);
}
return t;
}
void preorder(bitree t)
{
if(t)
{
printf("%c",t->data);
preorder(t->lchild);
preorder(t->rchild);
}
}
int main(int argc, char* argv[])
{
bitree t=NULL;
t=create(t);
preorder(t);
return 0;
}