图论深度优先遍历改进js实现
来源:3-5 图的深度优先遍历的改进

qq_crusader_1
2022-06-18
function GraphDFSImprove($G) { var order = [], G = $G; var visited = new Array(G.V()).fill(false) var dfs = function ($v) { visited[$v] = true; order.push($v); for (var w of G.adj($v)) { if (!visited[w]) { dfs(w); } } } this.order = function() { return order; } for (var i = 0; i < G.V(); i++) { if (!visited[i]) { dfs(i); } } } var g = new Graph('g1.txt'); var dfsImprove = new GraphDFSImprove(g); console.log('遍历的结果:', dfsImprove.order());
写回答
1回答
-
感谢分享,继续加油!:)
00
相似问题
深度优先遍历的优势?
回答 1
图深度优先遍历JS实现
回答 1