不明白为什么二叉树create仍然是NULL。。。
#include <stdio.h>
#include <stdlib.h>
typedef struct tree { //二叉树结构
char data;
struct tree *Llink;
struct tree *Rlink;
struct tree *Parent;
} BTNode,*BinTree;
void CreateTree(BinTree *bt) { //先序创建二叉树
char in;
while (scanf ("%c",&in)) {
if (in=='.') {
fflush (stdin);
*bt=NULL;
return;
} else {
fflush (stdin);
*bt=(BinTree)malloc(sizeof(BTNode));
(*bt)->data=in;
}
CreateTree (& ((*bt)->Llink));
CreateTree (& ((*bt)->Rlink));
}
}
int main( ) {
BinTree bt = NULL;
CreateTree(&bt);
if (bt==NULL) printf ("NULL");
}
在计算机科学中,二叉树是每个结点最多有两个子树的有序树。通常子树的根被称作“左子树”和“右子树”。
二叉树的第i层至多有2的 i -1次方个结点;深度为k的二叉树至多有2^(k) -1个结点。
对任何一棵二叉树T,如果其终端结点数(即叶子结点数)为n0,度为2的结点数为n2,则n0 = n2 + 1。