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
1 changed files with 7 additions and 5 deletions

View File

@ -29,11 +29,13 @@ public class Graph {
stack.push(start);
while (!stack.isEmpty()) {
int current = stack.pop();
isVisited[current] = true;
visit(current);
for (int dest : adjVertices.get(current)) {
if (!isVisited[dest])
stack.push(dest);
if(!isVisited[current]){
isVisited[current] = true;
visit(current);
for (int dest : adjVertices.get(current)) {
if (!isVisited[dest])
stack.push(dest);
}
}
}
}