Java Reference
In-Depth Information
if (findPath(r-1, c)) return true;
if (findPath(r, c+1)) return true;
if (findPath(r+1, c)) return true;
if (findPath(r, c-1)) return true;
G[r][c] = 0; //no path found; unmark
return false;
} //end findPath
public static void printMaze(PrintWriter out) {
int r, c;
for (r = 1; r <= m; r++) {
for (c = 1; c <= n; c++)
if (r == sr && c == sc) out.printf("S");
else if (G[r][c] == 0) out.printf(" ");
else if (G[r][c] == 1) out.printf("#");
else out.printf("x");
out.printf("\n");
}
} //end printMaze
} //end class Maze
Suppose the file maze.in contains the following:
8 10 6 6
1 1 1 1 1 1 1 1 1 1
1 0 1 0 0 0 1 0 0 1
1 0 1 0 1 0 1 1 0 1
1 0 0 0 1 0 0 0 0 1
1 0 1 1 1 1 1 1 0 1
1 0 1 0 1 0 1 1 0 0
1 0 0 0 0 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
Program P5.3 will write the following output to the file, maze.out :
##########
# #xxx# #
# #x#x## #
#xxx#xxxx#
#x######x#
#x# #S##xx
#xxxxx## #
##########
Search WWH ::




Custom Search