我这个用栈解迷宫程序哪里错了
#include<stdio.h>#include<stdlib.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,stack;
typedef struct{
int x;
int y;
}iterm;
int judge(pstack st)
{
if(st->top!=-1)
return 1;
else return 0;
}
void pop_stack(pstack S,Lacate *te)
{
*te=S->La[S->top];
S->top--;
}
pstack creat_stack()
{
pstack S;
S=(pstack)malloc(sizeof(pstack));
S->top=-1;
return S;
}
void push_stack(pstack S,Lacate te)
{
S->top++;
S->La[S->top]=te;
}
void mazepath(int maze[][10],iterm move[],int x0,int y0)
{
int x,y,d,i,j;
pstack s;
Lacate 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;
if(d<4)
{
i=x+move[d].x;j=y+move[d].y;
if(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;
}
else
d++;
}
}
}
int main()
{
int x=0,y=0;
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,x,y);
}