SOURCE

function MiddleTraverse(root) {
    const res = [];
    const stack = [];
    let cur = root;
    while (cur || stack.length) {
        while (cur) {
            stack.push(cur);
            cur = cur.left;
        }
        cur = stack.pop();
        res.push(cur);
        cur = cur.right;
    }
    return res;
}
console 命令行工具 X clear

                    
>
console