迷宫问题的思路
//2为重点,3为走不通,0为为走过,1为墙。
//注意if,else的东西,一定是先写if else,再写里面的东西、
public static boolean setWay(int[][] map,int i,int j){
if(map[6][5] == 2){ //到达终点
return true;
}else {
if(map[i][j] == 0){ //继续
map[i][j] = 2;
if(setWay(map,i+1,j)){ //向下走
return true;
}else if(setWay(map,i,j+1)){ //向右走
return true;
}else if(setWay(map,i-1,j)){ //向上走
return true;
}else if(setWay(map,i,j-1)){ //向左走
return true;
}else {
//走不通
map[i][j] = 3;
return false;
}
}else {
return false;
}
}
}
复试11-补充
最新推荐文章于 2023-04-20 16:09:25 发布