编了个迷宫问题的程序,结果现在用C报错,不知道该如何处理了?望大家帮忙修改 谢谢
#include<stdio.h>
#define m 4
#define n 4
#define NUM m*n
typedef struct
{ int x,y;
int pre;
}sqtype;
sqtype sq[NUM];
int maze[m+2][n+2]={{1,1,1,1,1,1},
{1,0,1,0,0,1},
{1,0,0,1,1,1},
{1,1,0,0,0,1},
{1,1,1,1,0,1},
{1,1,1,1,1,1}};
typedef struct
{ int dx;
int dy;
}moved;
moved move[8]={{-1,0},
{-1,1},
{0,1},
{1,1},
{1,0},
{1,-1},
{0,-1},
{-1,-1}};
int shortpath2()
{
int front,rear;
int x,y,i,j,v;
front=rear=0;
sq[0].x=1;
sq[0].y=1;
sq[0].pre=-1;
maze[1][1]=-1;
while(front<=rear)
{x=sq[front].x;y=sq[front].y;
for(v=0;v<8;v++)
{i=x+move[v].dx;j=x+move[v].dy;
if(maze[i][j]==0)
{ rear++;
sq[rear].x=i;sq[rear].y=j;sq[rear].pre=front;
maze[i][j]=-1;
}
if(i==m && j==n)
{ printpath(sq,rear);
restore(maze);
return 1;}
}
front++;
}
return 0;
}
void printpath(int rear)
{ int i;
i=rear;
do
{printf("(%d,%d)?",sq[i].x,sq[i].y);
i=sq[i].pre;
}while(i!=-1);
}
main()
{
int i,j;
int flag;
for(i=0;i<m+1;i++)
for(j=0;j<n+1;j++)
printf("%6d",maze[i][j]);
flag=shortpath2();
}