迷宫寻路问题

[复制链接]
查看11 | 回复2 | 2021-1-27 06:45:35 | 显示全部楼层 |阅读模式
如题,估计是栈的问题,初学者,求指教~

#include
#include
usingnamespacestd;
#defineMax5
typedefstruct{
intx;
inty;
intlen;
}point;
intmap[Max][Max];
intdir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
stacks;
intmain(){
intpathSearch(point);
freopen("in.txt","r",stdin);
for(inti=0;i=0&&q.y>=0&&q.x
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
感觉代码有点奇怪,在用栈,又在用递归,两者选其一吧
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
仅供参考:/**
*@Title老鼠走迷宫的拓展探究
*@Author孙琨
*@Date2013-11-16
*@AtXUST
*@AllCopyrightby孙琨
*
*/
#include
usingnamespacestd;
intmaze[9][9]={//初始化迷宫,英文maze为“迷宫”
{2,2,2,2,2,2,2,2,2},
{2,0,0,0,0,0,0,0,2},
{2,0,2,2,0,2,2,0,2},
{2,0,2,0,0,2,0,0,2},
{2,0,2,0,2,0,2,0,2},
{2,0,0,0,0,0,2,0,2},
{2,2,0,2,2,0,2,2,2},
{2,0,0,0,0,0,0,0,2},
{2,2,2,2,2,2,2,2,2}
};
intstartI=1,startJ=1;//入口行列坐标
intendI=7,endJ=7;//出口行列坐标
voidvisit(inti,intj)//自动搜寻路径
{
intm,n;
maze[j]=1;
if((i==endI)&&(j==endJ))
{
cout
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行