应该是二维数组传参有问题,把judge2和Mazesolving两个方法的maze参数的类型改成int (*maze)[4]就可以了,
这个4就是arr[4][4]里的第一个维大小,如果是arr[X][4],那这个4就要改成X(X是个常量)
#include<stdio.h>
#include<stdbool.h>
struct route {
int x;
int y;
};
typedef struct route route;
bool judge2(int(*maze)[4], int n, int m, route next) { //判断路径是否正确
if (next.x >= 0 && next.x < n
&& next.y >= 0 && next.y < m
&& maze[next.x][next.y] == 0) {
return true;
}
else {
return false;
}
}
bool Mazesolving(int (*maze)[4], int n, int m, route cur) { //迷宫求解
if (cur.x == n - 1 && cur.y == m - 1) { //找到出口
return true;
}
//将经过的路径做标记
route next;
maze[cur.x][cur.y] = 2;
//探索四个方向
next = cur;
next.y += 1; //右
if (judge2(maze, n, m, next)) {
if (Mazesolving(maze, n, m, next)) {
return true;
}
}
next = cur;
next.x += 1; //下
if (judge2(maze, n, m, next)) {
if (Mazesolving(maze, n, m, next)) {
return true;
}
}
next = cur;
next.y -= 1; //左
if (judge2(maze, n, m, next)) {
if (Mazesolving(maze, n, m, next)) {
return true;
}
}
next = cur;
next.x -= 1; //上
if (judge2(maze, n, m, next)) {
if (Mazesolving(maze, n, m, next)) {
return true;
}
}
//当为死路时
return false;
}
int main() {
int arr[4][4] = { {0,0,1,0}, //右下左上
{1,0,1,0},
{1,0,0,0} };
route cur = { 0,0 };
if (Mazesolving(arr, 4, 4, cur)) {
printf("该迷宫有出口\n");
}
else {
printf("无出口\n");
}
return 0;
}