# include<stdio.h>
# include<malloc.h>
# define TRUE 1
# define FALSE 0
typedef char DataType;
typedef struct Node {
DataType data;
struct Node* LChild;
struct Node* RChild;
}BiTNode, * BiTree;
BiTree T;
void CreateBiTree(BiTree* T) {
char ch;
ch = getchar();
if (ch == ' ')
*T = NULL;
else {
(*T) = (BiTree)malloc(sizeof(BiTNode));
(*T)->data = ch;
CreateBiTree(&((*T)->LChild));
CreateBiTree(&((*T)->RChild));
}
}
void PreOrder(BiTree T) {
if (T != NULL) {
printf("%c ", T->data);
PreOrder(T->LChild);
PreOrder(T->RChild);
}
}
void InOrder(BiTree T) {
if (T != NULL) {
InOrder(T->LChild);
printf("%c ", T->data);
InOrder(T->RChild);
}
}
void PostOrder(BiTree T) {
if (T != NULL) {
PostOrder(T->LChild);
PostOrder(T->RChild);
printf("%c ", T->data);
}
}
int count = 0;
void LeafCount(BiTree T) {
if (T != NULL) {
LeafCount(T->LChild);
LeafCount(T->RChild);
if (T->LChild == NULL && T->RChild == NULL)
count++;
}
}
int PostTreeDepth(BiTree T) {
int lh = 0, rh = 0, h;
if (T != NULL) {
lh = PostTreeDepth(T->LChild);
rh = PostTreeDepth(T->RChild);
h = lh > rh ? lh : rh;
return (h + 1);
}
else
return 0;
}
int main() {
CreateBiTree(&T);
printf("先序遍历:");
PreOrder(T);
printf("\n中序遍历:");
InOrder(T);
printf("\n后序遍历:");
PostOrder(T);
LeafCount(T);
printf("\n树的深度:%d", PostTreeDepth(T));
printf("\n叶结点数:%d", count);
return 0;
}