d,flag=0;ini_stack(&s);tmp.Dx=1;tmp.Dy=1;tmp.direct=-1;push_Stack(&s,tmp);while(!empty_Stack(&s)){tmp=pop_Stack(&s);x=tmp.Dx;y=tmp.Dy;d=tmp.direct+1;//遇到死路的时候,回溯(通过出栈完成)while(d<4){Px=x+MazeMove[d].x;Py=y+MazeMove[d].y;if(maze[Px][Py]==0){tmp.Dx=x;tmp.Dy=y;tmp.direct=d;push_Stack(&s,tmp);x=Px;y=Py;maze[x][y]=-1;/*标记,防止重复点*/if(x==m&&y==n){flag=1;printf("\n到达迷宫出口:%d,%d",x,y);printf("\n经过的节点有:%d个",size_stack(s));while(!empty_Stack(&s)){path=pop_Stack(&s);printf("\n(%d,%d,%d)",path.Dx,path.Dy,path.direct);}break;}elsed=0;}//结束ifelsed++;}//结束内部while}//结束外部whilereturnflag;}voidmain(){printf("请输入迷宫图的行数和列数(输入格式为i,j):\n");scanf("%d,%d",&m,&n);?printf("创建迷宫图:\n");?for(w=0;w<m+2;w++)?{for(t=0;t<n+2;t++)?{scanf("%d",&maze[w][t]);getchar();}}printf("\n找到迷宫的路径(yes/1,no/0):%d",Maze_path());?getch();}运行结果: