先序遍历:中、左、右
中序遍历:左、中、右
后序遍历:左、右、中
比如下面这科树
1
2 3
4 5 6 7
package com.sangfor.tree;
public class Node {
public int value;
public Node left;
public Node right;
public Node(int value) {
this.value = value;
}
}
package com.sangfor.tree;
public class ForEachTree {
public static void main(String[] args) {
Node node1 = new Node(1);
Node node2 = new Node(2);
Node node3 = new Node(3);
Node node4 = new Node(4);
Node nod
本文介绍了如何使用递归方法对二叉树进行先序(根-左-右)、中序(左-根-右)和后序(左-右-根)遍历。以一棵示例二叉树为例,阐述了具体的遍历过程和运行结果。
订阅专栏 解锁全文
734

被折叠的 条评论
为什么被折叠?



