My program accepts a char array as input file. The array is as follows:
"#########", "# # #", "# ## # #", "# # #", "### # ###", "# # # #", "# # #####", "# # #", "#########",
I use DFS and BFS to solve this maze, starting with [1,1] and ending with [width - 1, height - 1].
I was thinking of creating a tree representing the maze, and then traversing the tree using each algorithm, respectively.
I will start from each line and scan empty cells, in each empty cell each cell that is on the right, left and bottom will be a child of this cell. It looks something like this:
for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (isEmpty(maze[i][j])) { putChildren(maze[i-1][j], maze[i][j+1], maze[i+1][j]);
Is it a viable tactic to implement a tree like this and then use it to cross the tree using DFS and BFS, or should I go this other way?
source share