二叉树的创建与遍历问题???
#include <stdio.h>#include <stdlib.h>
typedef struct binarytree
{
char data;
struct binarytree *lchild;
struct binarytree *rchild;
}node;
typedef node* Btree;
void create(Btree *t)
{
char ch;
if((ch=getchar())=='#')
*t = NULL;
else
{
*t = (node *)malloc(sizeof(node));
(*t)->data = ch;
(*t)->lchild = (*t)->rchild = NULL;
create(&(*t)->lchild);
create(&(*t)->rchild);
}
}
void preorder(Btree t)
{
if(t!=NULL)
{
printf("%c\n",t->data);
preorder(t->lchild);
preorder(t->rchild);
}
}
void inorder(Btree t)
{
if(t!=NULL)
{
inorder(t->lchild);
printf("%c",t->data);
inorder(t->rchild);
}
}
void postorder(Btree t)
{
if(t!=NULL)
{
postorder(t->lchild);
postorder(t->rchild);
printf("%c",t->data);
}
}
int main(void)
{
Btree p=NULL;
create(&p);
printf("Preoder traverse:\n");
preorder(p);
printf("\n");
printf("Inorder traverse:\n");
inorder(p);
printf("\n");
printf("Postorder traverse:\n");
postorder(p);
printf("\n");
return 0;
}
为什么在输入#时没办法结束输入呢?