二叉树

------------恢复内容开始------------

递归序 每个节点都会 来到 三次 然后根据在每次来的时候,在哪一次操作,分为三种遍历,都是基于根节点为参考 - 先序, 头 左 右 - 中序, 左 头 右 - 后序, 左 右 头 递归实现 ```java public static class Node { int value; Node left; Node right; public Node(int value) { this.value = value; } } public static void preOrderRecur(Node head) { if (head == null) { return; } // 1 System.out.println(head.value + " "); preOrderRecur(head.left); // 2 preOrderRecur(head.right); // 3 } public static void inorderRecur(Node head) { if (head == null) { return; } // 1 inorderRecur(head.left); // 2 System.out.println(head.value + " "); inorderRecur(head.right); // 3 } public static void postorderRecur(Node head) { if (head == null) { return; } // 1 postorderRecur(head.left); // 2 postorderRecur(head.right); // 3 System.out.println(head.value + " "); } ``` ## 所有递归都可以改为非递归 ![](https://www.icode9.com/i/l/?n=22&i=blog/2827305/202205/2827305-20220503222203104-1510746552.png)

------------恢复内容结束------------

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...