大家好,我正在大学学习计算机 C 编程入门类(class),我们被要求做一个迷宫解决作业。我编写这段代码是为了找到迷宫的可达性和解决方案。我将包含所有迷宫元素的结构 M
传递给其中,然后使用递归来搜索迷宫。当我在其内部调用该函数时,我不确定要传递什么参数,因为当我尝试将参数作为 assign_reachability(&M)
传递时,我不断收到错误。如果您有任何建议或任何帮助,我将不胜感激。
谢谢
int
assign_reachability(maze_t *M){
int x, y;
x = M->XP;
y = M->YP;
if(M->maze[y][x].exit==EXIT){
return 1;
}
if(M->maze[y][x].type==NOGO || M->maze[y][x].visit==VISIT){
return 0;
}
M->maze[y][x].visit = VISIT;
/* check not on top row */
if(y!=0){
M->YP = (y-1);
if(assign_reachability(&M))
M->maze[y][x].reach=REACHABLE;
return 1;
}
/* check not on bottom row */
if(y!=((M->nrows)-1)){
M->YP = (y+1);
if(assign_reachability(&M))
M->maze[y][x].reach=REACHABLE;
return 1;
}
/* check not on left side */
if(x!=0){
M->XP = (x-1);
if(assign_reachability(&M))
M->maze[y][x].reach=REACHABLE;
return 1;
}
/* check not on right side */
if(x!=((M->ncolumns)-1)){
M->XP = (x+1);
if(assign_reachability(&M))
M->maze[y][x].reach=REACHABLE;
return 1;
}
return 0;
}
最佳答案
您正在返回 int
,但函数返回类型为 void
。
关于c - 通过递归将指针传递给结构(迷宫求解),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359079/