#include <bits/stdc++.h>
using namespace std;
typedef struct btnode{
char data;
struct btnode *lchild,*rchild;
}btnode,*bitree;
bitree creat_btnode(string s,int &i,int len)
{// 利用先序遍历创建二叉树
// 参数:先序遍历字符串s,字符串初始下标i=0,字符串长度len。
// 返回:二叉树
if(i>=len||s[i]=='#'){
i++;
return NULL;
}
bitree root =(bitree)malloc(sizeof(btnode));
root->data=s[i];
i++;
root->lchild=creat_btnode(s, i, len);
root->rchild=creat_btnode(s, i, len);
return root;
}
void miorder(bitree root)
// 二叉树的中序遍历
{
if(root!=NULL)
{
miorder(root->lchild);
cout<<root->data;
miorder(root->rchild);
}
}
int deep_bitree(bitree root)
{// 计算该二叉树的深度
int cnt=0;
if(!root)
return 0;
cnt=1+max(deep_bitree(root->lchild),deep_bitree(root->rchild));
return cnt;
}
int count_bitree(bitree root)
{// 计算该二叉树的总节点个数
if(!root)
return 0;
return 1+count_bitree(root->lchild)+count_bitree(root->rchild);
}
int count_Leaf_bitree(bitree root)
{// 计算该二叉树的叶子节点个数
if(!root)
return 0;
if(!root->lchild&&!root->rchild)
return 1;
return count_Leaf_bitree(root->lchild)+count_Leaf_bitree(root->rchild);
}
bitree bitreeshift(bitree root)
{
// 递归实现二叉树左右子树的交换
if(!root)
return NULL;
bitree temp=root->lchild;
root->lchild=root->rchild;
root->rchild=temp;
if(root->lchild!=NULL){
bitreeshift(root->lchild);
}
if(root->rchild!=NULL){
bitreeshift(root->rchild);
}
return root;
}
int main()
{
string s;
cin>>s;
int len=s.size();
int i=0;
bitree root=creat_btnode(s,i,len);
miorder(root);
cout<<endl;
cout<<deep_bitree(root)<<endl;
cout<<count_bitree(root)<<endl;
cout<<count_Leaf_bitree(root)<<endl;
return 0;
}