迷宫问题,运行不了,是为什么啊
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<conio.h>
#define m 8
#define N 8
#define STACK_SIZE N*N
#define TRUE 1
#define FALSE 0
typedef struct{
int a;
int b;
int dirt;
}element;
element stack[STACK_SIZE];
typedef struct{
int x;
int y;
}item;
item move[8];
int g;
int l;
int x1;
int x2;
int y1;
int y2;
int maze[N][N];
int mark[N][N];
void add(int *top,element Q){
if(*top>=STACK_SIZE-1){
printf("The stack is full\n");
return;
}
stack[++*top]=Q;
}
element delete_top(int *top){
if(*top==-1){
printf("the stack is empty \n");
exit(1);
}
return stack[(*top)--];
}
void shurukou(){
printf("\n输入迷宫的入口:\n");
scanf("%d%d",&x1,&y1);
printf("\n输入迷宫出口:\n");
scanf("%d%d",&x2,&y2);
}
void shuru (){
printf("输入行数:\n");
scanf("%d",&g);
printf("输入列数:\n");
scanf("%d",&l);
}
int showplay(int maze[][N])
{
int i,j;
printf("迷宫的矩阵如下: \n");
for(i=1;i<=g;i++)
{printf("\n");
for(j=1;j<=l;j++)
printf("%d",maze[i][j]);
}
}
int createmaze(int maze[][N]){
shuru();
int i,j;
for(i=1;i<=g;i++)
for(j=1;j<=l;j++)
maze[i][j]=(int)(rand()%2);
printf("自动生成迷宫中....\n");
showplay(maze);
shurukou();}
int tonglu(){
element *w;
int i,j;
for(i=0;i<m;i++)
for(j=0;j<N;j++)
printf("所有通路为(由下往上):\n");
w=stack;
while(w!=NULL)
{
printf("%d%d)\n",w.a,w.b);
w=w->next;
}
}
void path(void){
int i,j,a,b,next_a,next_b,dirt,found=FALSE;
element position;
int top=0;
mark[1][1]=1;
stack[0].a=1;
stack[0].b=1;
stack[0].dirt=1;
move[0].x=-1;move[0].y=0;
move[1].x=-1;move[1].y=1;
move[2].x=0;move[2].y=1;
move[3].x=1;move[3].y=1;
move[4].x=1;move[4].y=0;
move[5].x=1;move[5].y=-1;
move[6].x=0;move[6].y=-1;
move[7].x=-1;move[7].y=-1;
while(top>-1&&!found){
position=delete_top(&top);
a=position.a;
b=position.b;
while(dirt<8&&!found){
next_a=a+move[dirt].x;
next_b=b+move[dirt].y;
if(next_a==x2&&next_b==y2)
found=TRUE;
else if(!maze[next_a][next_b]&&!mark[next_a][next_b])
{
mark[next_a][next_b]=1;
position.a=a;
position.b=b;
position.dirt=++dirt;
add(&top,position);
a=next_a;
b=next_b;
dirt=0;
}
else ++dirt;
}
}
if(found)
{
tonglu();}
}
void main()
{
createmaze(int r[][]);
path();
}