您的位置:首页 > 其它

迷宫问题求解

2013-04-05 20:00 260 查看
Status MazePath(PosType start,PosType end) /* 算法3.3 */
{ /* 若迷宫maze中存在从入口start到出口end的通道,则求得一条 */
/* 存放在栈中(从栈底到栈顶),并返回TRUE;否则返回FALSE */
SqStack S;
SElemType e;
PosType curpos;
InitStack(&S);
curpos=start;
do{
if(Pass(curpos))
{
FootPrint(curpos);
e.ord=curstep;//通道块在路径上的序号
e.seat.x=curpos.x;
e.seat.y=curpos.y;
e.di=0;
Push(&S,e);
curstep++;
if(curpos.x==end.x&&curpos.y==end.y)
return TRUE;
curpos=NextPos(curpos,e.di);
}
else
{
if(!StackEmpty(S))
{
Pop(&S,&e);
curstep--;
while(e.di==3&&!StackEmpty(S)) /* 前一位置处于最后一个方向(北) */
{
MarkPrint(curpos);
Pop(&S,&e);
curstep--;
}
if(e.di<3)
{
e.di++;
Push(&S,e);
curstep++;
curpos=NextPos(curpos,e.di);
}
}
}
}while(!StackEmpty(S));
return FALSE;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息