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; }