深度优先遍历和广度优先遍历算法

  • A+
所属分类:算法

在线测试


function BFS( target, draw ){
      let stack = [target];
      while( stack.length > 0 ){
            let node = stack.shift();
            draw(node, draw);
            stack = stack.concat(Array.from(node.children).filter((node) =>{return node.nodeName !== "SCRIPT" && !node.dataset["nosearch"]}));
      }
}

function DFS( target, draw ){
      draw(target);
      Array.from(target.children).forEach((node) => {
            if( node.nodeName !== "SCRIPT" && !node.dataset["nosearch"] ){
                  DFS(node, draw);
            }
      })
}
weinxin
我的微信
欢迎来撩!!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: