#include<stdio.h>
#include<stdlib.h>
typedef struct BT
{
char data;
struct BT *lchild;
struct BT *rchild;
}BT;
BT *createtree()
{
BT *bt;
char x;
scanf("%c",&x);
if (x == '0')
bt = NULL;
else
{
bt = (BT *)malloc(sizeof(BT));
bt->data = x;
bt->lchild = createtree();
bt->rchild = createtree();
}
return (bt);
}
void Preorder(BT *bt)
{
if (bt != NULL)
{
printf("%c ",bt->data);
Preorder(bt->lchild);
Preorder(bt->rchild);
}
}
int count = 0;
void leafnum(BT *bt)
{
if (bt)
{
if (bt->lchild == NULL && bt->rchild == NULL)
{
count++;
}
leafnum(bt->lchild);
leafnum(bt->rchild);
}
}
void Nodenum(BT *bt)
{
if (bt)
{
count++;
Nodenum(bt->lchild);
Nodenum(bt->rchild);
}
}
int treedepth(BT *bt)
{
int ldepth, rdepth;
if (bt == NULL)
return 0;
else
{
ldepth = treedepth(bt->lchild);
rdepth = treedepth(bt->rchild);
if (ldepth > rdepth)
return (ldepth + 1);
else
return (rdepth + 1);
}
}
BT *search(BT *bt, char x)
{
if (bt->data == x)
return bt;
if (bt->lchild != NULL)
return (search(bt->lchild, x));
if (bt->rchild != NULL)
return (search(bt->rchild, x));
return NULL;
}