Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b764a12

Browse files
committed
修改二叉树的统一迭代法.md的Java版本注释笔误
1 parent ca183cd commit b764a12

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

problems/二叉树的统一迭代法.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class Solution {
238238
while (!st.empty()) {
239239
TreeNode node = st.peek();
240240
if (node != null) {
241-
st.pop(); // 将该节点弹出,避免重复操作,下面再将右中左节点添加到栈中
241+
st.pop(); // 将该节点弹出,避免重复操作,下面再将右左中节点添加到栈中(前序遍历-中左右,入栈顺序右左中)
242242
if (node.right!=null) st.push(node.right); // 添加右节点(空节点不入栈)
243243
if (node.left!=null) st.push(node.left); // 添加左节点(空节点不入栈)
244244
st.push(node); // 添加中节点
@@ -266,11 +266,10 @@ public List<Integer> inorderTraversal(TreeNode root) {
266266
while (!st.empty()) {
267267
TreeNode node = st.peek();
268268
if (node != null) {
269-
st.pop(); // 将该节点弹出,避免重复操作,下面再将右中左节点添加到栈中
269+
st.pop(); // 将该节点弹出,避免重复操作,下面再将右中左节点添加到栈中(中序遍历-左中右,入栈顺序右中左)
270270
if (node.right!=null) st.push(node.right); // 添加右节点(空节点不入栈)
271271
st.push(node); // 添加中节点
272272
st.push(null); // 中节点访问过,但是还没有处理,加入空节点做为标记。
273-
274273
if (node.left!=null) st.push(node.left); // 添加左节点(空节点不入栈)
275274
} else { // 只有遇到空节点的时候,才将下一个节点放进结果集
276275
st.pop(); // 将空节点弹出
@@ -294,7 +293,7 @@ class Solution {
294293
while (!st.empty()) {
295294
TreeNode node = st.peek();
296295
if (node != null) {
297-
st.pop(); // 将该节点弹出,避免重复操作,下面再将右中左节点添加到栈中
296+
st.pop(); // 将该节点弹出,避免重复操作,下面再将中右左节点添加到栈中(后序遍历-左右中,入栈顺序中右左)
298297
st.push(node); // 添加中节点
299298
st.push(null); // 中节点访问过,但是还没有处理,加入空节点做为标记。
300299
if (node.right!=null) st.push(node.right); // 添加右节点(空节点不入栈)
@@ -975,3 +974,4 @@ public IList<int> PostorderTraversal(TreeNode root)
975974
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
976975
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
977976
</a>
977+

0 commit comments

Comments
 (0)