参考资料:http://blog.csdn.net/u010442302/article/details/52713585
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
typedef struct node
{
char data;
struct node *L_Child,*R_Child;
}Tree;
void initTree(Tree *&T)
{
char str;
cin>>str;
if(str!='#')
{
T=(Tree *)malloc(sizeof(Tree));
T->data=str;
initTree(T->L_Child);
initTree(T->R_Child);
}
else T=NULL;
}
int Deepth_of_Tree(Tree *T)
{
if(T!=NULL)
{
int sum1=Deepth_of_Tree(T->L_Child);
int sum2=Deepth_of_Tree(T->R_Child);
if(fabs(sum1-sum2)>1)
{
cout<<"no!";
exit(0);
}
return (sum1++)>(sum2++)?sum1:sum2;
}
return 0;
}
int main()
{
Tree *T;
initTree(T);
Deepth_of_Tree(T);
cout<<"yes!";
return 0;
}