图深度优先遍历JS实现
来源:3-4 实现图的深度优先遍历
qq_crusader_1
2022-06-17
function GraphDFS($G) { var order = []; var G = $G; var visited = new Array(G.V()).fill(false) this.order = function() { return order; } var dfs = function($v) { visited[$v] = true; order.push($v); for (var w in G.adj($v)) { if (!visited[$v]) { dfs(w); } } } } var g = new Graph('g.txt'); var graphDFS = new GraphDFS(g); console.log(graphDFS.order());
写回答
1回答
-
感谢分享,继续加油!:)
012022-07-07
相似问题
深度优先遍历的优势?
回答 1
图论深度优先遍历改进js实现
回答 1