File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 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){ // 判断空树
122122 }
123123 }
124124
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
128128 }
129129 return Math .max (TreeDepth (treeNode .left ), TreeDepth (treeNode .right ))+1 ; // 递归调用左右子树 计算深度,并回溯深度+1
130130 }
Original file line number Diff line number Diff line change @@ -141,8 +141,8 @@ int TreeIsEmpty(CBTType treeNode){ // 判断空树
141141计算二叉树深度即计算二叉树中结点的最大层数,这里往往需要采用递归算法来实现。
142142``` java
143143int TreeDepth(CBTType treeNode){ // 计算二叉树深度
144- if (treeNode== null ){ // 递归临界条件
145- return 0 ; // 对于空树 深度为0
144+ if (treeNode== null ){ // 递归临界条件
145+ return 0 ; // 对于空树 深度为0
146146 }
147147 return Math . max(TreeDepth(treeNode. left), TreeDepth(treeNode. right))+ 1 ; // 递归调用左右子树 计算深度,并回溯深度+1
148148}
@@ -231,4 +231,5 @@ void LRDTree(CBTType treeNode){ // 后续遍历
231231}
232232```
233233## 数结构操作实例
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