#include<iostream>
using namespace std;
typedef struct tree
{
char data;
struct tree *lchild,*rchild;
}bitree; ios
void creattree(bitree *&T)
{
char data;
cin>>data;
if(data=='#')
T=NULL;
else
{
T=new(bitree);
T->data=data;
creattree(T->lchild);
creattree(T->rchild);
}
}
void preorder(bitree *T)
{
if(T)
{
cout<<T->data<<" ";
preorder(T->lchild);
preorder(T->rchild);
}
}
void inorder(bitree *T)
{
if(T)
{
inorder(T->lchild);
cout<<T->data<<" ";
inorder(T->rchild);
}
}
void fallorder(bitree *T)
{
if(T)
{
fallorder(T->lchild);
fallorder(T->rchild);
cout<<T->data<<" ";
}
} spa
int depth(bitree *T)
{
int ldep,rdep;
if(T==NULL)
return 0;
else
{
ldep=depth(T->lchild);
rdep=depth(T->rchild);
return ldep>rdep?ldep+1:rdep+1;
}
} ci
int sumleaf(bitree *T)
{
int sum=0,n,m;
if(T )
{
if((!T->lchild )&&(!T->rchild ))
sum++;
n=sumleaf(T->lchild);
sum+=n;
m=sumleaf(T->rchild);
sum+=m;
}
return sum;
} it
int main()
{
bitree *T=NULL;
creattree(T);
cout<<"pre:";
preorder(T);
cout<<endl;
cout<<"in :";
inorder(T);
cout<<endl;
cout<<"fal:";
fallorder(T);
cout<<endl;
cout<<"the depth:" ;
cout<<depth(T);
cout<<endl;
cout<<sumleaf(T);//根不算
return 0;
} io