Node node1 = new Node("a");
Node node2 = new Node("b");
Node node3 = new Node("c");
Node node4 = new Node("d");
Node node5 = new Node("e");
root = node1;
= node2;
= node3;
= node4;
= node5;
}
//求二叉树的深度
int length(Node root){
int depth1;
int depth2;
if(root == null) return 0;
//左子树的深度
depth1 = length();
//右子树的深度
depth2 = length();
if(depth1>depth2)
return depth1+1;
else
return depth2+1;
}
}
public class TestMatch{
public static void main(String[] args) {
BinaryTree tree = new BinaryTree();
();
(());
}
}
相关文章
- 二叉树的深度 Java
- 日撸 Java 三百行(21-30天,树与二叉树)
- Java 算法:图的深度优先遍历
- Java 算法:图的广度优先遍历
- java的nio之:java的bio流下实现的socket服务器同步阻塞模型和socket的伪异步的socket服务器的通信模型
- 安装Adroid SDK时出现找不到Java SDK的错误
- Java后台创建Socket服务接收硬件终端发送的数据
- java_web学习(六) request对象中的get和post差异
- Mysql中的字符串拆分方法 (类似java中split与PaAdmin库中的split_part函数)
- Java的密钥库jks文件放在/src/main/resources目录下报错的解决办法