广度优先遍历深度优先遍历 发表于 2017-11-21 | 分类于 js基础 深度优先遍历: 1234567function DFS(node) { if(!node) {return} console.log(node.nodeName); Array.from(node.children).forEach(child => {DFS(child)});} 广度优先遍历: 1234567891011function BFS(node) { var queue = [node]; while(queue.length) { var current = queue.shift(); console.log(current.nodeName); Array.from(current.children).forEach(child => queue.push(child)); }}