数据结构课程设计报—迷宫求解问题.docVIP

  • 12
  • 0
  • 约 21页
  • 2016-09-20 发布于贵州
  • 举报

数据结构课程设计报—迷宫求解问题.doc

数据结构课程设计报—迷宫求解问题

课题设计1:迷宫求解 一. 需求分析: 本程序是利首先由用户输入一组二维数组来组成迷宫,确认后程序自动运行,当迷宫有完整路径可以通过时,以0和1所组成的迷宫形式输出,标记所走过的路径结束程序;当迷宫无路径时,提示输入错误结束程序。 概要设计: 1.抽象数据类型定义: ADT Find{ 数据对象:D={ai?ai ElemSet,i=1,2,…,n,n≥0} 数据关系:R1={ai-1,ai?ai-1, aiD } 基本操作: ? ? ?? find (S) 初始条件:已初始化栈S,且栈为空 操作结果:从栈S中找出相对应的数据关系,并输出结果 }ADT Find 2. 主程序的流程以及各程序模块之间的调用关系: (1).定义变量i、j、w、z为整形变量 (2).输入迷宫二维数组maze(0:m,0:n) (3).调用子程序find () (4).结束程序 相应的源程序#includestdio.h #includestdlib.h typedef enum { ERROR, OK } Status; typedef struct { int row, line; }PosType; typedef struct { int di, ord; PosType seat; }SElemType; typedef struct { SElemType * base; SElemType * top; int stacksize; }SqStack; Status InitStack(SqStack S); Status Push(SqStack S,SElemType a); Status Pop(SqStack S,SElemType a); Status StackEmpty(SqStack S); Status MazePath(int maze[12][12],SqStack S, PosType start, PosType end); void Initmaze(int maze[12][12],int size); void printmaze(int maze[12][12],int size); Status Pass(int maze[12][12],PosType CurPos); void Markfoot(int maze[12][12], PosType CurPos); PosType NextPos(PosType CurPos, int Dir); void printpath(int maze[12][12],SqStack S,int size); void main (void) { SqStack S; int size,maze[12][12]; for(int n=0;n10;n++) { printf(创建一个正方形迷宫,请输入迷宫尺寸(注意不要大于50):\n); scanf(%d,size);if(size1 || size10){printf(输入错误!);return;} Initmaze(maze,size); printmaze(maze,size); PosType start,end; printf(输入入口行坐标和列坐标:);scanf(%d,start.row);scanf(%d,start.line); printf(输入出口行坐标和列坐标:);scanf(%d,end.row);scanf(%d,end.line); if(MazePath(maze,S,start,end)) printpath(maze,S,size); else printf(找不到通路!\n\n); } } Status MazePath(int maze[12][12],SqStack S, PosType start, PosType end) { PosType curpos; int curstep; SElemType e; In

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档