getNextLoc
method (with error)
public Location getNextLoc(int row, int col)
{
int belowValue = Integer.MAX_VALUE;
int rightValue = Integer.MAX_VALUE;
if(row < grid.length - 1)
belowValue = grid[row + 1][col];
if(col < grid[0].length - 1)
rightValue = grid[row][col + 1];
if(belowValue < rightValue)
return new Location(row + 1, col);
else
return new Location(row, col + 1);
}
This solution fails to account for the situation in which one of the values does not exist and the other is equal to Integer.MAX_VALUE
. My test code has been updated to catch this error.
I was trying to avoid repeatedly constructing Location
objects. I got a little too fancy.
See my correct GridPath solution.