Update depth-first-search.english.md (#34856)

Fixed formatting for the solution to increase readability. It was previously difficult to see since the code was all one line
This commit is contained in:
Dan B 2019-01-25 20:12:45 -08:00 committed by Paul Gamble
parent bc50e4e6da
commit ce63de866c

View File

@ -76,7 +76,26 @@ console.log(dfs(exDFSGraph, 3));
```js
function dfs(graph, root) { var stack = []; var tempV; var visited = []; var tempVNeighbors = []; stack.push(root); while (stack.length > 0) { tempV = stack.pop(); if (visited.indexOf(tempV) == -1) { visited.push(tempV); tempVNeighbors = graph[tempV]; for (var i = 0; i < tempVNeighbors.length; i++) { if (tempVNeighbors[i] == 1) { stack.push(i); }}}} return visited;}
function dfs(graph, root) {
var stack = [];
var tempV;
var visited = [];
var tempVNeighbors = [];
stack.push(root);
while (stack.length > 0) {
tempV = stack.pop();
if (visited.indexOf(tempV) == -1) {
visited.push(tempV);
tempVNeighbors = graph[tempV];
for (var i = 0; i < tempVNeighbors.length; i++) {
if (tempVNeighbors[i] == 1) {
stack.push(i);
}
}
}
}
return visited;
}
```
</section>