中序遍历示例
先打印左边的,再打印当前的,再打印右边的
class Node {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
let a = new Node("a");
let b = new Node("b")
let c = new Node("c")
let d = new Node("d")
let e = new Node("e")
let f = new Node("f")
let g = new Node("g")
a.left = c
a.right = b
c.left = f
c.right = g
b.left = d
b.right = e
function fl(root) {
if(root == undefined) return;
fl(root.left)
console.log(root.value)
fl(root.right)
}
fl(a)