{"ScriptPreparationCode":"function *dfs(root) {\r\n yield root;\r\n for (let child of root.children) {\r\n yield *dfs(child);\r\n }\r\n}\r\n\r\n\r\nfunction *bfsArray(root) {\r\n let queue = [root];\r\n do {\r\n let node = queue.shift();\r\n yield node;\r\n queue.push(...node.children);\r\n } while (queue.length);\r\n}\r\n\r\n\r\nfunction *bfsLinkedList(root) {\r\n let head = {node: root, next: null};\r\n let tail = head;\r\n\r\n do {\r\n let node = head.node;\r\n yield node;\r\n\r\n for (let child of node.children) {\r\n tail = tail.next = {node: child, next: null};\r\n }\r\n\r\n head = head.next;\r\n } while (head !== null);\r\n}\r\n\r\n\r\nfunction makeRandomTree(depth, degree) {\r\n let node = {\r\n data: Math.round(Math.random() * 100),\r\n children: []\r\n };\r\n\r\n if (depth !== 0)\r\n for (let i = 0; i \u003C degree; \u002B\u002Bi) {\r\n node.children.push(makeRandomTree(depth - 1, degree));\r\n }\r\n\r\n return node;\r\n}\r\n\r\nconst testTree = makeRandomTree(7, 5);","TestCases":[{"Name":"Pre-order","Code":"for (let node of dfs(testTree)) {node.data;}","IsDeferred":false},{"Name":"Level-order with array","Code":"for (let node of bfsArray(testTree)) {node.data;}","IsDeferred":false},{"Name":"Level-order with linked list","Code":"for (let node of bfsLinkedList(testTree)) {node.data;}","IsDeferred":false}]}