高分跪求c++迷宫求解问题 (要用深度优先和广度优先两种方法)

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:45:24
RT
现有一个M*N的迷宫,迷宫的地图用二维数组存储。其中,0表示此顶点可以通过,1表示不能通过。试编程找到从任意一点(x1,y1)到任意一点(x2,y2)的【最短】路径。
路径不要直接输出,要先用一种结构把它存起来,找到最短路径后,再一起输出。

P.S.
M,N是变量。
要用深度优先和广度优先两种方法实现。
找到的那条路径一定是最短的。
以左上角为原点,右下角坐标为(M,N)
有代码+较为详尽的注释者,另有加分!
急求,在线等!!!
回一楼,我要C++的,不是C的。。
能帮忙把注释改成中文的嘛?英文的看不太懂。。

很久以前做的,现在都忘记了。你看一下吧。我的报告,也可以发给你,不过还是期望你自己可以学会怎么做,少年智则国智。C++和C一回事,你把其中的语法规则改一下就好,比如输入输出语句,将结构体改成类,也可不改,都支持的。

#include "stdio.h"
#include "conio.h" /*provide the support of getch */
#define max 10
#define maxlength (max*max) /*the max lenth of the path*/
#define zdir 4 /*the total direction*/
#include "graphics.h" /*provide the support of graphics*/
#include "dos.h" /* provide the support of function:sleep */
#include "time.h" /* provide the support of sleep */
#define M 10 /*the max lenth of the map*/
#define N 10 /*the max lenth of the map*/
/*the following four function are stating functions*/
void printmap(void);
int zfindpath(int row,int col,int erow,int ecol);
void creategraphich(int n1,int n2,int n3,int n4);
void creategraphich(int n1,int n2,int n3,int n4);
int zmap[max][max]={ {1,1,1,1,1,1,1,1,1,1},