Merge pull request #10869 from omertopuz/patch-1

Update Graph.java
This commit is contained in:
Loredana Crusoveanu 2021-09-19 15:19:11 +03:00 committed by GitHub
commit ae17173f90

View File

@ -29,6 +29,7 @@ public class Graph {
stack.push(start); stack.push(start);
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
int current = stack.pop(); int current = stack.pop();
if(!isVisited[current]){
isVisited[current] = true; isVisited[current] = true;
visit(current); visit(current);
for (int dest : adjVertices.get(current)) { for (int dest : adjVertices.get(current)) {
@ -37,6 +38,7 @@ public class Graph {
} }
} }
} }
}
public void dfs(int start) { public void dfs(int start) {
boolean[] isVisited = new boolean[adjVertices.size()]; boolean[] isVisited = new boolean[adjVertices.size()];