We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents bf7f4b3 + b9a95d3 commit 3979cb1Copy full SHA for 3979cb1
1 file changed
algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java
@@ -29,11 +29,13 @@ public void dfsWithoutRecursion(int start) {
29
stack.push(start);
30
while (!stack.isEmpty()) {
31
int current = stack.pop();
32
- isVisited[current] = true;
33
- visit(current);
34
- for (int dest : adjVertices.get(current)) {
35
- if (!isVisited[dest])
36
- stack.push(dest);
+ if(!isVisited[current]){
+ isVisited[current] = true;
+ visit(current);
+ for (int dest : adjVertices.get(current)) {
+ if (!isVisited[dest])
37
+ stack.push(dest);
38
+ }
39
}
40
41
0 commit comments