前序遍历(先根次序遍历)
    先打印当前的,再打印左边的,再打印右边的。
    如下代码

    1. class Node {
    2. constructor(value) {
    3. this.value = value;
    4. this.left - null;
    5. this.right = null;
    6. }
    7. }
    8. let a = new Node("A")
    9. let b = new Node("B")
    10. let c = new Node("C")
    11. let d = new Node("D")
    12. let e = new Node("E")
    13. let f = new Node("F")
    14. let g = new Node("G")
    15. a.left = c;
    16. a.right = b;
    17. c.left = f;
    18. c.right = g;
    19. b.left = d;
    20. b.right = e
    21. function fl(root){
    22. if(root == null) return;
    23. console.log(root.value)
    24. fl(root.left)
    25. fl(root.right)
    26. }
    27. fl(a)