不懂,请求帮忙?
#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);
}
return t;
}
void preorder(bitree t)
{
if(t)
{
printf("%c",t->data);
preorder(t->lchild); //例如右子数的有两个结点,这个函数是如何读取右子数第二个结点的?
}
}
void preorder_1(bitree t)
{
if(t)
{
preorder(t->lchild);
printf("%c\n",t->data);
preorder(t->rchild);
}
}
int main(int argc, char* argv[])
{
bitree t;
t=create(t);
preorder(t);
fflush(stdin);
t->rchild=create(t);
preorder(t->rchild);
fflush(stdin);
preorder_1(t);
return 0;
}