求二叉树的深度
来源:互联网 发布:js validate 验证 编辑:程序博客网 时间:2024/04/30 07:39
求二叉树的深度,实现过程如下所示:
package cn.edu.nwu.structs.tree;/** * @author jcm * *时间 2016年9月3日 */public class GetBinaryTreeDepth {public static void main(String[] args) {BinaryTreeNode root = CreateBinaryTree.createBinaryTree();int depth = getBinaryTreeDepth(root);System.out.println(depth);}/** * @author jcm * 求二叉树的深度 * @param root 树根 * @return 返回树的深度 */public static int getBinaryTreeDepth(BinaryTreeNode root){if(root == null){return 0;}int depth = 0;int leftDepth = 0;int rightDepth = 0;leftDepth = getBinaryTreeDepth(root.leftTreeNode);rightDepth = getBinaryTreeDepth(root.rightTreeNode);depth = 1 + (leftDepth>rightDepth?leftDepth:rightDepth);return depth;}}
0 0
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 求二叉树的深度
- 2016.09.01 69.9kg WTF
- lucence 概念(二)
- Get技能---如何压缩图片文件大小不失真
- 大数据环境基础之Centos安装Haoop集群(2)在CentOS上安装jdk
- ArcGIS10.2下载安装 License Manager、ArcGIS Desktop、ArcGIS Server软件下载及破解
- 求二叉树的深度
- 多少个1组成的整数可以被2011整除?
- XML
- http状态码
- PAT乙级.1038. 统计同成绩学生(20)
- lucence 示例 (三)
- 第三章pmtest2源码解析 实模式到保护模式再到实模式
- codeforces 711D Directed Roads(DFS)
- ios developer tiny share-20160901