{"ScriptPreparationCode":"root = {val: 1001}\r\nlet i = 0, node = root\r\nwhile (\u002B\u002Bi \u003C 1000) {\r\n while (node) {\r\n if (i \u003C node.val) {\r\n if (!node.left) {\r\n node.left = { val: i }\r\n break\r\n }\r\n node = node.left\r\n } else {\r\n if (!node.right) {\r\n node.right = { val: i }\r\n break\r\n }\r\n node = node.right\r\n }\r\n }\r\n}","TestCases":[{"Name":"DFS","Code":"function dfs(node) {\r\n if (!node) return\r\n dfs(node.left)\r\n dfs(node.right)\r\n}\r\ndfs(root)","IsDeferred":false},{"Name":"BFS (shift)","Code":"let q = [root]\r\nwhile (q.length) {\r\n const node = q.shift()\r\n if (node.left) q.push(node.left)\r\n if (node.right) q.push(node.right)\r\n}","IsDeferred":false},{"Name":"BFS (pop)","Code":"let q = [root]\r\nwhile (q.length) {\r\n const node = q.pop()\r\n if (node.right) q.push(node.right)\r\n if (node.left) q.push(node.left)\r\n}","IsDeferred":false},{"Name":"BFS (reassign queue)","Code":"let q = [root]\r\nwhile (q.length) {\r\n const level = []\r\n const node = q.pop()\r\n if (node.left) level.push(node.left)\r\n if (node.right) level.push(node.right)\r\n q = level\r\n}","IsDeferred":false},{"Name":"BFS (reassign node, shift)","Code":"let q = [], node = root\r\nwhile (node) {\r\n if (node.left) q.push(node.left)\r\n if (node.right) q.push(node.right)\r\n node = q.shift()\r\n}","IsDeferred":false},{"Name":"BFS (reassign node, pop)","Code":"let q = [], node = root\r\nwhile (node) {\r\n if (node.right) q.push(node.right)\r\n if (node.left) q.push(node.left)\r\n node = q.pop()\r\n}","IsDeferred":false}]}