数据结构课程设计-迷宫求解.doc
《数据结构课程设计-迷宫求解.doc》由会员分享,可在线阅读,更多相关《数据结构课程设计-迷宫求解.doc(14页珍藏版)》请在三一办公上搜索。
1、精选优质文档-倾情为你奉上 数据结构课程设计 迷宫求解 学院:湖北工业大学计算机学院 教师:沈华老师 班级:12网络工程1班 学号: 姓名:饶进阳 时间:2013年12月22日 目 录问题描述 . 2思路解析 . 3程序流程 . 4核心代码 . 5源程序代码 . 6程序运行实例 . 12课设总结 . 14 1 迷宫求解问题描述:可以输入一个任意大小的迷宫数据,用非递归的方法求出一条走出迷宫的路径,并将路径输出;要求:在上交资料中请写明:存储结构、基本算法(可以使用程序流程图)、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法;比如这是一个迷宫电脑找出的出路 2 思 路设定当
2、前位置的初值为入口位置:do若当前位置可通,则将当前位置插入栈顶;若该位置是出口位置,则结束;否则切换当前位置的东邻块为新的当前位置;否则若栈不空且栈顶位置还有其他方向未被探索,则设定新的当前位置为沿顺时针方向旋转找到的栈顶位置的下一相邻块;若栈不空但栈顶位置的四周均不可通,则删去栈顶位置;若栈不空,则重新测试新的栈顶位置,直至找到一个可通的相邻块或出栈至栈空;while(栈不空)栈空说明没有路径存在PS:类似动态求解方法 3 程序流程 第一次用visio做程序框图,所以只把程序的大概流程画出来了。 4 核心代码/栈相关操作int initlStack(Stack *S)int pushSta
3、ck(Stack S, coordinate e)int popStack(Stack S, coordinate *e)int getTop(Stack S, coordinate *e)void show(Stack S)/创建一个迷宫int creatMaze(Maze *m)/打印出一个迷宫void showMaze(Maze *m)/求当前结点的下一个通路coordinate passNext(Maze *m, int i, int j)/求迷宫路径int solveMaze(Maze *m, Stack S)/模拟出路径void showRoad(Maze m, Stack S)
4、5程序源码:#include #include #define MAX 100#define SIZE sizeof(Node)/*/栈typedef struct int x;/行int y;/列coordinate;/坐标typedef struct nodecoordinate data;struct node *next;Node, *Stack;/栈的相关操作/栈初始化/带头结点的链栈int initlStack(Stack *S) (*S) = (Node *)malloc(SIZE);if(*S) = NULL) return 1;(*S)-next = NULL;return
5、0;/入栈int pushStack(Stack S, coordinate e) Node *p;p = (Node *)malloc(SIZE);p-data.x = e.x;p-data.y = e.y;p-next = S-next;S-next = p;return 0;/出栈int popStack(Stack S, coordinate *e) Node *p;if(S-next = NULL) printf(nStack is empty!n);return 2;e-x = S-next-data.x;e-y = S-next-data.y;p = S-next;S-next
6、= p-next;free(p);return 0;/读取栈顶int getTop(Stack S, coordinate *e) e-x = S-next-data.x;e-y = S-next-data.y;return 0;/显示void show(Stack S) Node *p;p = S-next;while(p != NULL) printf(%d %d data.x, p-data.y);p = p-next;printf(startn);/*/*/迷宫typedef struct int row;int col;int arrMAXMAX;Maze;/创建一个迷宫int cr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 课程设计 迷宫 求解

链接地址:https://www.31ppt.com/p-2792890.html