验证中...
私信发送成功
语言: C/C++
分类: 常用工具包
最后更新于 2017-12-07 23:52
main.cpp
原始数据 复制代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
/**
* 二叉树数据结构
*/
typedef struct BiTNode{
char data;
struct BiTNode *lchild, *rchild;
} *BiTree;
/**
* 获取二叉树的深度
* @param T
* @return
*/
int get_BiTree_depth(BiTree T){
if(T == NULL)
return 0;
int lchilddepth = get_BiTree_depth(T->lchild);
int rchilddepth = get_BiTree_depth(T->rchild);
return lchilddepth > rchilddepth ? lchilddepth+1 : rchilddepth+1;
}
int main() {
BiTree t;
BiTree b1;
BiTree b2;
BiTree b3;
BiTree b4;
BiTree b5;
BiTree b6;
t = (BiTNode*)malloc(sizeof(BiTNode));
t->data = 'A';
b1 = (BiTNode*)malloc(sizeof(BiTNode));
b1->data = 'B';
b2 = (BiTNode*)malloc(sizeof(BiTNode));
b2->data = 'C';
b3 = (BiTNode*)malloc(sizeof(BiTNode));
b3->data = 'D';
b4 = (BiTNode*)malloc(sizeof(BiTNode));
b4->data = 'E';
b5 = (BiTNode*)malloc(sizeof(BiTNode));
b5->data = 'F';
b6 = (BiTNode*)malloc(sizeof(BiTNode));
b6->data = 'G';
t->lchild = b1;
t->rchild = b2;
b1->lchild = b3;
b1->rchild = b4;
b2->rchild = b5;
b5->rchild = b6;
cout << get_BiTree_depth(t);
return 0;
}

评论列表( 0 )

你可以在登录后,对此项目发表评论

4_float_left_people 4_float_left_close