这个迷宫把我弄迷了,哪位大哥大姐指点一下
#include<stdio.h>#define m 6
#define n 8
#define MAXSIZE 100
typedef struct{
int x;
int y;
int d;
}Lacate;
typedef struct{
Lacate La[MAXSIZE];
int top;
}*pstack ;
typedef struct{
int x;
int y;
}*iterm;
int judge(pstack *st);
void pop_stack(pstack S,Locate *te);
void push_stack(pstack S,Lacate te);
void mazepath(int maze[][n+2],iterm move[],int x0,int y0);
void detroy(pstack S);
int main()
{
int a[m+2][n+2]={1,1,1,1,1,1,1,1,1,1,
1,0,1,1,1,0,1,1,1,1,
1,0,0,0,0,1,1,1,1,1,
1,0,1,0,0,0,0,0,1,1,
1,0,1,1,1,0,0,1,1,1,
1,1,0,0,1,1,0,0,0,1,
1,0,1,1,0,0,1,1,0,1,
1,1,1,1,1,1,1,1,1,1};
iterm m[4]={{1,0},{-1,0},{0,1},{0,-1}};
mazepath(a,m,1,1);
}
int judge(pstack st)
{
if(st->top!=-1)
return 1;
else return 0;
}
void pop_stack(pstack S,Locate *te)
{
te=S->La[S->top];
S->top--;
}
pstack creat_stack()
{
pstack S;
S=(pstack)malloc(sizeof(pstack));
if(S)
S->top=-1;
return S;
}
void push_stack(pstack S,Lacate te)
{
S->top++;
S->La[S->top]=te;
}
void detroy(pstack S)
{
if(S)
free(S);
S=NULL;
return;
}
void mazepath(int maze[][n+2],iterm move[],int x0,int y0)
{
int x,y,d,i,j;
pstack s;
Locate term;
x=x0;y=y0;d=-1;
term.x=x0;term.y=y0;term.d=d;
s=creat_stack();
push_stack(s,term);
if(judge(s))
{
pop_stack(s,&term);
x=term.x;y=term.y;d=term.d+1;
while(d<4)
{
i=x+move[d].x;j=y+move[d].y;
while(maze[i][j]!=1)
{
term.x=x;term.y=y;term.d=d;
push_stack(s,&term);
x=i;y=j;
maze[x][y]=-1;
if(x==m&&y==n)
{
while(judge(s)
{
pop_stack(s,&term);
printf("(%d,%d)-",term.x,term.y);
}
}
else d=0;
}
d++;
}
}
destroy_stack(s);
}