From c2d8da314510274dab62d0be92f8ae6138c01ad8 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 3 Nov 2021 21:17:12 +0530 Subject: java/DFS: Keep variables in smallest scope --- algorithms/java/DFS.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'algorithms') diff --git a/algorithms/java/DFS.java b/algorithms/java/DFS.java index 61b2027..8d1e341 100644 --- a/algorithms/java/DFS.java +++ b/algorithms/java/DFS.java @@ -1,5 +1,5 @@ public class DFS { - private static final int[][] directions = new int[][]{ + static int[][] directions = new int[][]{ {+0, +1}, // Right. {+1, +0}, // Down. {+0, -1}, // Left. @@ -7,12 +7,9 @@ public class DFS { }; static void traverse(int x, int y, char[][] maze, boolean[][] visited) { - int curx; - int cury; - for (int i = 0; i < 4; i++) { - curx = x + directions[i][0]; - cury = y + directions[i][1]; + int curx = x + directions[i][0]; + int cury = y + directions[i][1]; // Out of bounds check. if (curx < 0 || cury < 0 -- cgit 1.4.1-2-gfad0