aboutsummaryrefslogtreecommitdiffstats
path: root/algorithms/java
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-11-03 21:34:02 +0530
committerAndinus <andinus@nand.sh>2021-11-03 21:34:02 +0530
commite1e90993013b15b63409859fba8476de4da6924d (patch)
tree90a92e07838371c34763ef44c374bbd1b216c3e3 /algorithms/java
parent35d406dd138c06a4e200789a1934d691d37af851 (diff)
downloadfornax-e1e90993013b15b63409859fba8476de4da6924d.tar.gz
java/DFS: Fix out of bounds check
Diffstat (limited to 'algorithms/java')
-rw-r--r--algorithms/java/DFS.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/algorithms/java/DFS.java b/algorithms/java/DFS.java
index e2f866e..ba3d8d8 100644
--- a/algorithms/java/DFS.java
+++ b/algorithms/java/DFS.java
@@ -21,7 +21,7 @@ public class DFS {
// Out of bounds check.
if (curx < 0 || cury < 0
- || curx > maze.length - 1 || cury > maze.length - 1)
+ || curx > maze.length - 1 || cury > maze[0].length - 1)
continue;
// Marker cells.
@@ -40,8 +40,8 @@ public class DFS {
System.out.println();
// Found a solution, exiting.
- if (maze[curx][cury] == '$')
- System.exit(0);
+ // if (maze[curx][cury] == '$')
+ // System.exit(0);
if (visited[curx][cury]) {
continue;
@@ -57,7 +57,11 @@ public class DFS {
char[][] maze = {
{'.', '#', '.'},
{'.', '.', '.'},
- {'.', '.', '$'}
+ {'.', '#', '.'},
+ {'.', '.', '.'},
+ {'.', '.', '#'},
+ {'.', '#', '.'},
+ {'.', '.', '$'},
};
boolean[][] visited = new boolean[maze.length][maze[0].length];