问题描述
以后再做8个方向的,先把问题简化成四个方向
设置0代表墙,1代表路,2代表刚刚走过的路径;
1,2,3,4分别表示上、右、下、左四个方向 ,每一步都按照1,2,3,4的顺序进行判断
题目要求用栈保存走过的路径,除此之外,我设置了一个隐藏的和迷宫大小相等的二维整型数组side_maze[N][M],用于存储已经在迷宫的某格子上往某方向走过一次的对应的数字(1-4)
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#define N 10
#define M 10
typedef struct//迷宫中某格的xy坐标,和刚刚走向下一格子的方向
{
int x;
int y;
int direction;
}POSITION;
typedef struct
{
POSITION p[N*M];
int top;
}STACK;
void InitStack(STACK *s)
{
s->top=-1;
}
void PushStack(STACK *s,int x,int y,int d)//入栈
{
if(s->top==N*M)
{
printf("栈满!\n");
return;
}
s->p[++s->top].x=x;
s->p[s->top].y=y;
s->p[s->top].directi