# include "stdio.h"
# include "stdlib.h"
# include "malloc.h"
typedef struct Node{
char data; //定义根结点
struct Node *lchild; //定义左子树
struct Node *rchild; //定义右子树
}Node,*BiTree;
int JianShu(BiTree &T) { //构造二叉链表表示的二叉树T,按先序遍历输入二
//叉树中结点的值(一个字符),空格字符表示空树.
char e;
T=(Node *)malloc(sizeof(Node)); //开辟一个以sizeof(Node)为单位的空间
if(!T) //开辟失败
exit (-2);
fflush(stdin); //清空缓存
scanf ("%c",&e);
if(e==' ')
T=NULL;
else {
T->data=e; // 生成根结点
printf ("请输入%c 的左孩子:",e);
JianShu(T->lchild); // 构造左子树
printf ("请输入%c 的右孩子:",e);
JianShu(T->rchild); // 构造右子树
}
return 1;
}
int DLR_P(BiTree &T) { //先序遍历打印二叉树中所有数据
if (T!=NULL) { //非空二叉树
printf ("%c ",T->data); //访问T
DLR_P(T->lchild); //递归遍历左子树
DLR_P(T->rchild); //递归遍历右子树
}
return 1;
}
int LDR_P(BiTree &T) { //中序遍历打印二叉树中所有数据
if (T!=NULL) { //非空二叉树
LDR_P(T->lchild); //递归遍历左子树
printf ("%c ",T->data); //访问T
LDR_P(T->rchild); //递归遍历右子树
}
return 1;
}
int LRD_P(BiTree &T) { //后序遍历打印二叉树中所有数据
if (T!=NULL) { //非空二叉树
LRD_P(T->lchild); //递归遍历左子树
LRD_P(T->rchild); //递归遍历右子树
printf ("%c ",T->data); //访问T
}
return 1;
}
int DLR_0(BiTree &T,int &s_0) { //用先序遍历求二叉树T 中所有叶子总数
if (T!=NULL) {