---
title: "Discussion on \"二叉树的遍历\" | Hashnode"
description: "Discussion on \"二叉树的遍历\". 掌握两种方法进行二叉树的遍历，这里重点看迭代法是怎么写，迭代法使用栈来模拟递归中的栈，也可以使用一种通用方式进行前、中、后序遍历。\n递归法\ndef dfs(root) {\n    // 前序遍历\n    dfs(root.left)\n    // 中序遍历\n    dfs(root.right)\n    // 后序遍历\n}\n\n迭代法：迭代法是用 stack 栈来模拟递归栈\n下面这种写法可以统一前序、中序、后序遍历方式的写法，只需要改变入栈顺序\n前序遍历：中，左，右中序遍历：左，中，右后序遍历：左..."
url: "https://hashnode.com/posts/5lqm5yj5qcr55qe6ygn5y6g/660db0a6e0419be50fda0f01"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [二叉树的遍历](https://zhengsongling.com/5lqm5yj5qcr55qe6ygn5y6g?utm_source=hashnode&utm_medium=feed)

掌握两种方法进行二叉树的遍历，这里重点看迭代法是怎么写，迭代法使用栈来模拟递归中的栈，也可以使用一种通用方式进行前、中、后序遍历。 递归法 def dfs(root) { // 前序遍历 dfs(root.left) // 中序遍历 dfs(root.right) // 后序遍历 } 迭代法：迭代法是用 stack 栈来模拟递归栈 下面这种写法可以统一前序、中序、后序遍历方式的写法，只需要改变入栈顺序 前序遍历：中，左，右中序遍历：左，中，右后序遍历：左...

Apr 3, 2024 · 2 min read · zhengsongling.com  
Read the article

-   [#5lqm5yj5qcr](https://hashnode.com/tag/5lqm5yj5qcr)

## Written by

[zhengsl](https://hashnode.com/@zhengsl)

@zhengsl

  
[View profile](https://hashnode.com/@zhengsl)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
