#include <iostream>
using namespace std;
#define N 10
#include <stack>
struct pos
{
int _row;// 行
int _col;// 列
};
bool cheakstep(pos a)
{
if(a._col > -1||a._col < N-1||
a._row > -1||a._row < N-1)
{
return true ;
}
return false ;
}
bool IsPath(int arr[][N],pos nowloction,stack<pos>& s)
{
pos tmp = nowloction;
//入栈标记 栈不为空
s.push (nowloction);
arr[tmp._row][tmp._col] = 2;
while(!s.empty ())
{
//shang
pos now = s.top ();
if(now._row == N-1)
{
return true ;
}
now._row -=1;
if(cheakstep(now)==true && arr[now._row][now._col]==0)
{
s.push (now);
arr[now._row ][now._col ]=2;
continue;
}
//you
now = s.top ();
now._col +=1
【数据结构】用栈实现迷宫
最新推荐文章于 2024-05-31 08:58:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)