I have created a MazeSolver android app for a school project. I am using stacks to hold the coordinate positions of the path taken to solve the maze. I have written this helper method to return the coordinates as a string, from cell (0,0) to the last cell of the solved maze.
private String generateSolutionString()
{
ArrayList<String> list = new ArrayList<String>();
while (!path.isEmpty())
{
String temp = path.top().toString();
list.add(0, temp);
path.pop();
}
String solution = "";
boolean first = true;
for (String s : list)
{
if (first)
{
solution += s;
first = false;
}
solution += " " + s;
}
return solution;
}
I have also overridden the toString() method:
public String toString()
{
return "(" + getX() + ", " + getY() + ")";
}
However, when it changes the statusLabel to the path, it is printing two (0,0) coordinates at the beginning. Why is it doing this?
I think you meant for
to be
else