#include<iostream>
#include<cstdlib>
using namespace std;
int M = 0;
typedef struct node
{
char 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;
}
void Du(Tree *&T,int n)
{
if(T!=NULL)
{
Du(T->r,n+1);
Du(T->l,1);
}
if(M<n) M = n;
}
int main()
{
Tree *T;
Init(T);
int n = 0;
if(T->r==NULL)
{
Du(T,n);
cout<<M-1;
}
else cout<<"ERROR";
return 0;
}
SWUST数据结构--输出利用二叉树存储的普通树的度
最新推荐文章于 2024-04-23 18:17:06 发布