{ printf("栈初始化失败");
return(0);
}
Push_SeqStack (S,temp) ; /* 迷宫入口点入栈 */
while (! Empty_SeqStack (S ) )
{
Pop_SeqStack(S,&temp);
x=temp.x ; y=temp.y ; d=temp.d+1 ;
while (d<4) /*存在剩余方向可以搜索 */
{
i=x+move[d].x ; j=y+move[d].y ;
if( maze[i][j]==0 ) /*此方向可走*/
{
temp.x=x;temp.y=y; temp.d=d;
Push_SeqStack ( S, temp ) ;/*点{x,y}可以走,用栈保存可以走的路径*/ x=i; y=j; maze[x][y]= -1;
if (x==m&&y==n) /*迷宫有路*/
{
while( !Empty_SeqStack(S) )
{
Pop_SeqStack (S,&temp) ;
printf("(%d,%d)<- ",temp.x,temp.y) ;/*打印可走的路径*/ }
Destroy_SeqStack(&S); /*销毁栈*/
return 1 ;
}
else d=0 ;/*方向复位,从第一个方向开始试探*/
}
else d++ ;/*试探下一个方向*/
} /*while (d<4)*/
} /*while */
Destroy_SeqStack(&S); /*销毁栈*/
return 0 ;/*迷宫无路*/
}
/*递归算法*/
int mazepath1(int maze[][n+2],item move[],int x,int y)
{/*求迷宫路径,入口参数:迷宫数组,下标移动的增量数组,开始点(x,y), 以及开始点对应的步数step,(m,n)是终点,返回值:1表示求出路径,0表示无路径*/
int i;
int step=0;
step++;
maze[x][y]=step;