My program is taking a char array as input from a file. The array looks like this:
"#########",
"# # #",
"# ## # #",
"# # #",
"### # ###",
"# # # #",
"# # #####",
"# # #",
"#########",
I am implementing DFS and BFS to solve this maze with starting from [1,1] and ending in [width - 1,height - 1].
I thought of making a tree representing the maze and then traversing the tree using each algorithm respectively.
I will start at each row and scan for empty cells, at each empty cell every cell that is to its right, left and bottom are going to be children of that 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]);
//this will check if it's a wall first
}
}
Is it a viable tactic to implement the tree like this and then use it to traverse the tree with DFS and BFS or I should I go at this another way?