File tree 2 files changed +7
-6
lines changed
2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -122,9 +122,9 @@ int TreeIsEmpty(CBTType treeNode){ // 判断空树
122
122
}
123
123
}
124
124
125
- int TreeDepth (CBTType treeNode ){ // 计算二叉树深度
126
- if (treeNode ==null ){ // 递归临界条件
127
- return 0 ; // 对于空树 深度为0
125
+ int TreeDepth (CBTType treeNode ){ // 计算二叉树深度
126
+ if (treeNode ==null ){ // 递归临界条件
127
+ return 0 ; // 对于空树 深度为0
128
128
}
129
129
return Math .max (TreeDepth (treeNode .left ), TreeDepth (treeNode .right ))+1 ; // 递归调用左右子树 计算深度,并回溯深度+1
130
130
}
Original file line number Diff line number Diff line change @@ -141,8 +141,8 @@ int TreeIsEmpty(CBTType treeNode){ // 判断空树
141
141
计算二叉树深度即计算二叉树中结点的最大层数,这里往往需要采用递归算法来实现。
142
142
``` java
143
143
int TreeDepth(CBTType treeNode){ // 计算二叉树深度
144
- if (treeNode== null ){ // 递归临界条件
145
- return 0 ; // 对于空树 深度为0
144
+ if (treeNode== null ){ // 递归临界条件
145
+ return 0 ; // 对于空树 深度为0
146
146
}
147
147
return Math . max(TreeDepth(treeNode. left), TreeDepth(treeNode. right))+ 1 ; // 递归调用左右子树 计算深度,并回溯深度+1
148
148
}
@@ -231,4 +231,5 @@ void LRDTree(CBTType treeNode){ // 后续遍历
231
231
}
232
232
```
233
233
## 数结构操作实例
234
- [ BinaryTree.java] ( ./BinaryTree.java )
234
+ [ BinaryTree.java] ( ./BinaryTree.java )
235
+ <div align =" center " >[*****回到首页*****](/offer-java)
You can’t perform that action at this time.
0 commit comments