- 论坛徽章:
- 0
|
Status MazePath(MazeType maze,PositionType start,PositionType end)
{
SqStack s;
 ositionType curpos;
int curstep; // 1->east, 2->south,3->west,4->north
SElemType *e;
curpos=start;
curstep=1;
if(InitStack(&s)==TRUE){
do{
if(Pass(maze,curpos,&s)==TRUE){
FootPrint(maze,curpos);
e->order=curstep;
e->seat=curpos;
e->dir=1;
 ush(&s,e);
if(curpos.r==end.r && curpos.c==end.c){
if(DestoryStack(&s)==TRUE)
return TRUE;
exit(0);
}
else{
curpos=NextPos(curpos,1);
curstep++;
}
}
else{
if(StackEmpty(&s)!=TRUE)
 op(&s,e);
while(e->dir==4 && StackEmpty(&s)!=TRUE){
MarkPrint(maze,e->seat);
 op(&s,e);
}
if(e->dir<4){
e->dir++;
 ush(&s,e);
curpos=NextPos(e->seat,e->dir);
}
}
}while(StackEmpty(&s)!=TRUE);
}
}
main()
{
MazeType maze;
 ositionType start,end;
start.r=1;
start.c=1;
end.r=8;
end.c=8;
char a[][MAXLEN]={
{'1','1','1','1','1','1','1','1','1','1'},
{'1','0','0','0','0','1','1','1','1','1'},
{'1','1','0','0','1','1','1','1','1','1'},
{'1','0','1','0','0','0','1','1','1','1'},
{'1','0','1','0','1','0','1','1','1','1'},
{'1','0','1','0','0','0','1','1','1','1'},
{'1','1','1','1','1','0','0','0','1','1'},
{'1','1','1','1','1','1','1','0','0','1'},
{'1','1','1','1','1','1','1','1','0','1'},
{'1','0','1','1','1','1','1','1','1','1'}
};
char *p1,*p2;
int i,j;
p1=(char *)maze.adr;
p2=(char *)a;
for(i=0;i<(sizeof(a)/sizeof(char));i++)
*p1++=*p2++;
if(MazePath(maze,start,end)!=TRUE)
printf("No path from entrance to exit \n");
else
 rintMaze(maze);
}
|
|
|