关注公众号程序猿从入门到入土查询更方便哦
#include <iostream>
#include <stdio.h>
#define MAXSIZE 10000
using namespace std;
typedef struct bitnode{
char data;
struct bitnode* lChild,*rChild;
}BiTNode,*BiTree;
char a;
void CreateBiTree(BiTree &t){
cin>>a;
if(a=='@'){
t=NULL;
}
else{
t=new BiTNode;
t->data=a;
CreateBiTree(t->lChild);
CreateBiTree(t->rChild);
}
}
int Depth(BiTree t){
int m=0,n=0;
if(t==NULL){
return 0;
}
else{
m=Depth(t->lChild);
n=Depth(t->rChild);
if(m>n){
return m+1;
}
else{
return n+1;
}
}
}
void PreOutBiTree(BiTree t){
if(t){
cout<<t->data<<" ";
PreOutBiTree(t->lChild);
PreOutBiTree(t->rChild);
}
}
int main()
{
BiTree t;
char dataArr[MAXSIZE];
CreateBiTree(t);
//PreOutBiTree(t);
cout<<Depth(t)<<endl;
return 0;
}