深度优先遍历

let deepTraversal1 = (node, nodeList = []) => {
  if (node !== null) {
    nodeList.push(node);
    let children = node.children;
    for (let i = 0; i < children.length; i++) {
      deepTraversal1(children[i], nodeList);
    }
  }
  return nodeList;
};

 

posted @ 2019-09-23 19:03  单先生  阅读(185)  评论(0编辑  收藏  举报