#include<iostream>
#include<stdio.h>
using namespace std;
#define status int
typedef struct BiTNtree
{
char data;
struct BiTNtree *rchild;
struct BiTNtree *lchild;
}BNtree,*Btree;
void CreatBtree(Btree &t)
{
char ch;
cin>>ch;
if(ch=='#')
{
t=NULL;
}
else
{
t=new BNtree;
t->data=ch;
CreatBtree(t->lchild );
CreatBtree(t->rchild );
}
}
//----------------------------------------------------------------------------
//遍历
void PreOrderTraver(Btree t)//先序遍历
{
if(!t)
return ;
cout<<t->data<<" ";
PreOrderTraver(t->lchild);
PreOrderTraver(t->rchild);
}
void InOrderTraver(Btree t)//中序遍历
{
if(!t)
return ;
InOrderTraver(t->lchild);
cout<<t->data<<" ";
InOrderTraver(t->rchild);
}
void PosOrderTraver(Btree t)//后序遍历
{
if(t==NULL)
return ;
PosOrderTraver(t->lchild);
PosOrderTraver(t->rchild);
cout<<t->data<<" ";
}
//-----------------------------------------------------------------------
int ans=0;
void countleef(Btree t)
{
if(t)
{
if(t->lchild ==NULL&&t->rchild ==NULL)
{
ans++;
}
countleef(t->lchild );
countleef(t->rchild );
}
else
return;
}
// int Leaf2(BTree T)//分治法统计叶子节点数目
// {
// int count;
// if(T==NULL)
// count=0;
// else if(T->Lchild==NULL&&T->Rchild==NULL)
// count=1;
// else
// count=Leaf2(T->Lchild)+Leaf2(T->Rchild);
// return count;
// }
//------------------------------------------------------------------
int jie(Btree t)
{
if(t)
{
return jie(t->lchild )+jie(t->rchild )+1;
}
else
return 0;
}
int Treepath(Btree t)
{
if(t==NULL)
{
return 0;
}
int rtree=Treepath(t->lchild );
int ltree=Treepath(t->rchild );
return rtree>ltree?rtree+1:ltree+1;
}
int main()
{
Btree t;
CreatBtree(t);
cout<<Treepath(t);
}
#include<stdio.h>
using namespace std;
#define status int
typedef struct BiTNtree
{
char data;
struct BiTNtree *rchild;
struct BiTNtree *lchild;
}BNtree,*Btree;
void CreatBtree(Btree &t)
{
char ch;
cin>>ch;
if(ch=='#')
{
t=NULL;
}
else
{
t=new BNtree;
t->data=ch;
CreatBtree(t->lchild );
CreatBtree(t->rchild );
}
}
//----------------------------------------------------------------------------
//遍历
void PreOrderTraver(Btree t)//先序遍历
{
if(!t)
return ;
cout<<t->data<<" ";
PreOrderTraver(t->lchild);
PreOrderTraver(t->rchild);
}
void InOrderTraver(Btree t)//中序遍历
{
if(!t)
return ;
InOrderTraver(t->lchild);
cout<<t->data<<" ";
InOrderTraver(t->rchild);
}
void PosOrderTraver(Btree t)//后序遍历
{
if(t==NULL)
return ;
PosOrderTraver(t->lchild);
PosOrderTraver(t->rchild);
cout<<t->data<<" ";
}
//-----------------------------------------------------------------------
int ans=0;
void countleef(Btree t)
{
if(t)
{
if(t->lchild ==NULL&&t->rchild ==NULL)
{
ans++;
}
countleef(t->lchild );
countleef(t->rchild );
}
else
return;
}
// int Leaf2(BTree T)//分治法统计叶子节点数目
// {
// int count;
// if(T==NULL)
// count=0;
// else if(T->Lchild==NULL&&T->Rchild==NULL)
// count=1;
// else
// count=Leaf2(T->Lchild)+Leaf2(T->Rchild);
// return count;
// }
//------------------------------------------------------------------
int jie(Btree t)
{
if(t)
{
return jie(t->lchild )+jie(t->rchild )+1;
}
else
return 0;
}
int Treepath(Btree t)
{
if(t==NULL)
{
return 0;
}
int rtree=Treepath(t->lchild );
int ltree=Treepath(t->rchild );
return rtree>ltree?rtree+1:ltree+1;
}
int main()
{
Btree t;
CreatBtree(t);
cout<<Treepath(t);
}