Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

N 叉树的层序遍历

Sunny-117 opened this issue · comments

commented
N 叉树的层序遍历
function traversalMultipleTree(root) {
  if (!root) {
    return;
  }
  let queue = [root];
  while (queue.length > 0) {
    let node = queue.shift();
    console.log(node.value);
    if (node.children) {
      for (let i = 0; i < node.children.length; i++) {
        queue.push(node.children[i]);
      }
    }
  }
}