6-7 求二叉树的深度 (6 分)
 

本题要求实现一个函数,可返回二叉树的深度。

函数接口定义:


int Depth(BiTree T);

T是二叉树树根指针,函数Depth返回二叉树的深度,若树为空,返回0。

裁判测试程序样例:


#include <stdio.h>
#include <stdlib.h> typedef char ElemType;
typedef struct BiTNode
{
ElemType data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree; BiTree Create();/* 细节在此不表 */ int Depth(BiTree T); int main()
{
BiTree T = Create(); printf("%d\n", Depth(T));
return 0;
}
/* 你的代码将被嵌在这里 */

输出样例(对于图中给出的树):

4
int Depth(BiTree T){
if(T==NULL)
return 0;
int a=Depth(T->lchild);
int b=Depth(T->rchild);
if(a>b)
return a+1;
else
return b+1;
}

最新文章

  1. sql指定插入自增长id的数据
  2. iOS 学习 - 10下载(3) NSURLSession 音乐 篇
  3. mysql5.6启动占用内存很大的解决方法
  4. 终于有了自己的园子,Happy一下
  5. C#语言的Image和byte数组的互相转换
  6. BZOJ2375: 疯狂的涂色
  7. linux ssh 无密码登陆
  8. 慕课linux学习笔记(五)常用命令(2)
  9. Struts 2.3.4.1完整示例
  10. 连接linux主机
  11. iOS imageio nsurlsession 渐进式图片下载
  12. ActiveMQ与spring整合
  13. cocos creator 中的粒子效果
  14. mysql中文查询问题
  15. 【算法】LeetCode算法题-Two Sum
  16. 爬虫基础02-day24
  17. copy on write,代理模式
  18. Mybatis 事务管理和缓存机制
  19. Android 简单介绍图片压缩和图片内存缓存
  20. Azure 怎么开通FTP

热门文章

  1. 记一次getshell
  2. VSCode 在 Vue 导入路径中使用 @ 符号后无法正确跳转 bug
  3. website 性能检测 &amp; 前端性能优化
  4. CSS3 &amp; transition &amp; animation
  5. Regular Expressions all in one
  6. nodejs 显示进度条插件
  7. Android混合Flutter
  8. 稳定币USDN的算法调控
  9. 适合Linux嵌入式项目的代码构建与依赖管理工具——cazel
  10. hadoop的lzo支持