#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct node
{
int data;
struct node *l,*r;
}Tree;
void Init(Tree *&T)
{
char str;
cin>>str;
if(str!='#')
{
T=(Tree *)malloc(sizeof(Tree));
T->data=str;
Init(T->l);
Init(T->r);
}
else T=NULL;
}
int Deep(Tree *&T)
{
if(T==NULL) return 0;
int sum1=0,sum2=0;
sum1=Deep(T->l);
sum2=Deep(T->r);
if(sum1>sum2) return sum1+1;
else return sum2+1;
}
int main()
{
Tree *T;
Init(T);
cout<<Deep(T);
return 0;
}
SWUST数据结构--先序遍历创建二叉树的深度
最新推荐文章于 2022-05-10 17:36:20 发布
