请帮忙指导一下下面程序(迷宫问题 运行结果出错啦!)
#include<iostream>#include<stack>
#include<list>
using namespace std;
#define Row 10
#define Col 10
typedef struct{
int row,col;
}Seat;
typedef struct
{
Seat se;
int di;
}ElemType;
void ShowMaze(int Maze[Row][Col])
{
for(int i=0;i<10;++i)
{
for(int j=0;j<10;++j)
{
cout<<Maze[i][j]<<" ";
}
cout<<endl;
}
}
Seat NextPos(Seat &Curpos, int di)
{
//返回当前节点的下一节点
Seat seat = Curpos;
switch(di)
{
case 1: //东
seat.col++;
break;
case 2: //南
seat.row++;
break;
case 3: //西
seat.col--;
break;
case 4: //北
seat.row--;
break;
}
return seat;
}
void FootPrint(int Maze[Row][Col],Seat CurPos)
{
Maze[CurPos.row][CurPos.col]=2;
}
bool Pass(int Maze[Row][Col],Seat CurPos)
{
if (Maze[CurPos.row][CurPos.col]==0)
{
return true;
}
else return false;
}
void MarkPrint(int Maze[Row][Col],Seat seat)
{
Maze[seat.row][seat.col]=3;
}
bool MazePath(int Maze[Row][Col],Seat start,Seat end)
{
Seat CurPos = start;
ElemType e;
stack<ElemType> st;
do
{
if (Pass(Maze,CurPos))
{
e.se=CurPos;
e.di=1;
st.push(e);
FootPrint(Maze,CurPos);
if ((CurPos.row==end.row)&&(CurPos.col==end.col))
{
return true;
}
else
{
CurPos=NextPos(CurPos,e.di);
}
}
else
{
if (!st.empty())
{
e=st.top ();
st.pop();
while((e.di==4)&&(!st.empty()))
{
MarkPrint(Maze,e.se);
e= st.top();
st.pop (); //退回一步
}
if(e.di<4)
{
e.di++;
st.push(e);
CurPos=NextPos(e.se,e.di);
}
}
}
} while (!st.empty());
return false;
}
void main()
{
Seat start={1,0};
Seat end={8,9};
int Maze[Row][Col]={
{1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,1,1,1,1},
{1,0,1,1,1,0,0,1,1,1},
{1,0,0,1,1,0,1,1,1,1},
{1,1,0,0,0,1,1,1,1,1},
{1,0,0,1,0,0,0,0,0,1},
{1,0,1,0,0,1,1,1,1,1},
{1,0,1,0,1,1,0,0,0,1},
{1,0,1,0,0,0,0,1,0,1},
{1,1,1,1,1,1,1,1,0,1}};
ShowMaze(Maze);
MazePath(Maze,start,end);
cout<<endl;
ShowMaze(Maze);
}