SOURCE

// 广度遍历
function BFS (root) {
    if (!root) return []
    let stack = [root]
    let result = []
    while (stack.length) {
        let node = stack.pop()
        node && result.push(node.value)
        node.left && stack.unshift(node.left)
        node.right && stack.unshift(node.right)
    }
    return root
}

// 深度遍历

// ----------------  先序遍历 -------------------

// 递归遍历
function DLR (root) {
    let result = []
    (function fn(node) {
        if (node) {
            result.push(node.value)
            fn(node.left)
            fn(node.right)
        }
    })(root)
    return result
}

// 迭代遍历
function secondDLR (root) {
    if (!root) return []
    let stack = [root]
    let result = []
    while (stack.length) {
        let node = stack.pop()
        node && result.push(node.value)
        node.right && result.push(node.right)
        node.left && result.push(node.left)
    }    
}
console 命令行工具 X clear

                    
>
console