当前位置:首页 > 迷宫程序设计报告(c语言)
迷宫运行是的一些结果:
以下迷宫是教材上p50 图-3.4的迷宫:
接下:
以上两个界面为程序运行时分割的两部分。
编辑是遇到的困难:
首先,经过多次调试,程序已经没有错误了,但是在运行后,迷宫路径总是不能完整表示出来。多次查找原因后才知道自己对一些函数结果状态代码定义错误。例如:将error、FALSE定义为-1、-2,。将其定义为0后则能正确表现迷宫路径。
之后,我又想除了自己手动创建迷宫之外,能不能在一个结构类型中定义一个mazetype maze2.a{【maxlen】【maxlen】,使其初始化并附值,当要用时直接调用就可以了,但是照这样做了之后,总是发现有错误。我想可能是文件后缀名得原因,可能在cpp文件不能这样用,所以索性就部编辑了,让函数只有一个功能。
迷宫程序源代码:
//迷宫程序 2011/4/3 #include
#define max_stacksize 100 #define increase_size 10 #define maxlen 10
typedef struct
{ int row; int col;
}postype; //坐标位置类型
typedef struct { int ord; postype seat; int di;
}elemtype; //栈的元素类型
typedef struct sqstack { elemtype *base; elemtype *top; int stacksize;
}sqstack; //栈类型
typedef struct mazetype { int row; int col; char a[maxlen][maxlen]; }mazetype; //迷宫类型
int Initmaze(mazetype &maze);
int mazepath(mazetype &maze,postype start,postype end); int Initstack(sqstack &s);
int push(sqstack &s,elemtype e); int pop(sqstack &s,elemtype &e); int stackempty(sqstack &s);
int gettop(sqstack &s,elemtype &e); int destroystack(sqstack &s);
int pass(mazetype &maze,postype curpos); int footprint(mazetype &maze,postype curpos); int markprint(mazetype &maze,postype curpos); postype nextpos(postype &curpos,int i); void outputmaze(mazetype &maze);
void main() { int i,j;
char cn;
postype start,end; mazetype maze; do{ do { printf(\手动创建迷宫******************\\n\ Initmaze(maze); printf(\迷宫输出图为****************\\n\ outputmaze(maze); printf(\请输入迷宫入口坐标:\ scanf(\ if(start.row>maze.row||start.col>maze.col) { printf(\输入坐标有误!\\n\ continue; } }while(start.row>maze.row||start.col>maze.col); printf(\请输入迷宫出口坐标:\ scanf(\ if(!mazepath(maze,start,end)) printf(\迷宫没有出口路径!******************\\n\ else { printf(\输出迷宫路径('*'表示迷宫通道路径,'@'表示曾走过但不能走通的标记)************\\n\ outputmaze(maze); } //case 2: // { // mazetype maze2; // maze2.a[maxlen][maxlen]=;{{1,1,1,1,1,1,1,1,1,1;};{1,0,0,1,0,0,0,1,0,1;};{1,0,0,1,0,0,0,1,0,1;}; // {1,0,0,0,0,1,1,0,0,1;};{1,0,1,1,1,0,0,0,0,1;};{1,0,0,0,1,0,0,0,0,1;};{1,0,1,0,0,0,1,0,0,1;}; // {1,0,1,1,1,0,1,1,0,1;};{1,1,0,0,0,0,0,0,0,1;};{1,1,1,1,1,1,1,1,1,1;}}; // } printf(\是否继续-----------y:继续 n:结束\\n\ scanf(\ }while(cn=='y'||cn=='n');
共分享92篇相关文档