// Tree struct
typedef struct tree
{
ElemType data;
struct tree * lchild;
struct tree * rchild;
}TreeNode,* Tree;
void CreateTree(Tree* t)
{
char ch;
scanf("%c",&ch);
if ( ch == '#' ){
*t = NULL;
}
else
{
*t = (Tree)malloc(sizeof(TreeNode));
if ( !(*t) )
{
printf("memory allocate error!");
return ;
}
(*t)->data = ch;
CreateTree(&((*t)->lchild));
CreateTree(&((*t)->rchild));
}
return ;
}
int main()
{
Tree T;
printf("\nPlease input node in preorder way,'#'means NULL:");
CreateTree(T);
}
程序执行到CreateTree里面无法退出,递归退出判断条件如何写?
终端输入2次 # 回车