recursive alg question
ok, i have a 8x16 grid of ints. if the grid has a 3 it is an empty space. if it has a 0 it is what im looking for, and if it has a 1 then its a path, basically
33333333
33333333
33333333
33333333
33333333
33333133
33331133
33311333
33311333
33303333
33333333
33333333
31333333
31133333
33113333
33333333
ok so grid[0][0] is 3... and grid[9][3] = 0its grid[y][x]..
you pass the function a cell that is a 1 in the grid and it checks to see if there is a path to a 0 only using 1's.. soo if you pass any of the cells through the function on the top they should return 1 and if you try to run the function on any of the lower set of 1's it would return 0 because there is no 0 connected to them by 1's
I tried setting up a recursive solution to this..
looks like this:
findAZero(int xCoord,int yCoord)
{
int left=0;
int right=0;
int down=0;
if(xCoord<min || xCoord >max)
{return 0}
if(yCoord<min || yCoord > max)
{return 0}
if(grid[y][x] == 0
{
return 1;
}
if(grid[y][x]==3)
{
return 0;
}
if(grid[y][x]==1)
{
left= findAZero(xCoord-1,yCoord);
right=findAZero(xCood+1,yCoord);
down=findAZero(xCoord,yCoord+1);
}
return left+right+down;
}
doesnt work how I want it, can i get some help/tips/suggestions
thanks

