题目是 任意输入二叉树的结点个数和结点值,构造一棵二叉树,采用三种递归遍历
算法(前序、中序、后序)对这颗二叉树进行遍历并计算出二叉树的高度。
遇到的现象和发生背景,请写出第一个错误
我写的代码为什么直接结束了
运行结果及详细报错内容
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
char data;
struct Node *LChild;
struct Node *RChild;
}BiTNode, *BiTree;
void CreateBiTree(BiTree bt);
int PostTreeHeight(BiTree bt);
int main()
{
BiTree *bt;
int a;
CreateBiTree(*bt);
a=PostTreeHeight(*bt);
printf("树的高度为%d",a);
return 0;
}
void CreateBiTree(BiTree bt)
{
char ch;
ch=getchar();
if(ch=='.') bt=NULL;
else
{
bt=(BiTree)malloc(sizeof(BiTNode));
(bt)->data=ch;
CreateBiTree(((bt)->LChild));
CreateBiTree(((bt)->RChild));
}
}
int PostTreeHeight(BiTree bt)
{
int hl,hr,max;
if(bt!=NULL)
{
hl=PostTreeHeight(bt->LChild);
hr=PostTreeHeight(bt->RChild);
max=hl>hr?hl:hr;
return (max+1);
}
else return(0);
}