2022年数据结构迷宫问题源代码 .pdf





《2022年数据结构迷宫问题源代码 .pdf》由会员分享,可在线阅读,更多相关《2022年数据结构迷宫问题源代码 .pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数据结构迷宫问题源代码#include<stdio.h> #include<malloc.h> #include<stdlib.h> #include <conio.h> #include"typedef.h" #include "ADTStack.h" #include"maze.h" #include"CONSTANT.h" #define MAXLEN 15 #define TRUE 1 #define FALSE 0 #define OK 1 #define
2、ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 #define NULL 0 PosType start; PosType end; MazeType maze; bool found; #define MAXLEN 15/ 迷宫包括外墙最大行列数目#define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int Status; / 坐标位置类型typedef
3、 struct int r,c; PosType;/ 迷宫中 r 行 c 列的位置/ 迷宫类型typedef struct int step; PosType seat; / 当前的坐标位置int di; / 往下一坐标位置的方向名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - ElemType; / 结点类型typedef struct ElemType *base; ElemType *top; int size; Stac
4、k; Status FootPrint(MazeType maze,PosType curpos); Status MarkPrint(MazeType maze,PosType curpos); void PrintMaze(MazeType maze); Status MazePath(MazeType maze,PosType start,PosType end); void InitMaze(MazeType maze, char aMAXLENMAXLEN, int row, int col); Status Pass(MazeType maze, PosType curpos);
5、PosType NextPos(PosType curpos,int i); typedef struct NodeType ElemType data; NodeType *next; NodeType,*LinkType; / 栈类型typedef struct int r; int c; char arrMAXLENMAXLEN;/ 可取 ' ','*','','#' MazeType; Status InitStack(Stack &S); /InitStack Status Push(Stack &S,E
6、lemType e) ; Status Pop(Stack &S, ElemType &e) ; Status DestroyStack(Stack &S); /DestroyStack void ClearStack(Stack &S); /ClearStack Status StackEmpty(Stack S); /StackEmpty int StackLength(Stack S); void StackTraverse(Stack S, Status(*visit)(ElemType e); 名师资料总结 - - -精品资料欢迎下载 - - - -
7、- - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 10 页 - - - - - - - - - / 创建栈void Initialization() printf("n*"); printf("n * CreatMaze-c MazePath-m PrintMaze Quit*"); printf("n*"); printf("n * Operation: *"); printf("n*"); printf("nn ent
8、er a operation code:c,m,p,q:"); / 读入操作命令符,显示提示信息void ReadCommand(char &cmd) do cmd=getche(); while(!(cmd='c'|cmd='m'|cmd='p'); / 解释 ch-具体执行void Interpret(char cmd) switch(cmd) case 'c': int rnum, cnum, i=0,m=1,n=1; char a2MAXLENMAXLEN; char input20; char data
9、1000; printf("n请输入迷宫数据文件名!n"); scanf("%s",input); FILE *fp; fp=fopen(input,"r"); if(!fp) printf("n不能打开文件n"); break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 10 页 - - - - - - - - - while(!feof(fp) fscanf(fp,"%s&
10、quot;,&datai); if(i=0) rnum=(int )datai-(int)'0' if(i=1) cnum=(int)datai-(int)'0' if(i>=2) if(n>cnum)m+;n=1; a2mn=datai; n+; i+; fclose(fp); InitMaze(maze, a2, rnum, cnum); printf("n迷宫建立完成!n"); break; case 'm': printf("n请输入迷宫入口的坐标,以空格为间隔:-"); sca
11、nf("%d %d",&start.r,&start.c); printf("n请输入迷宫出口的坐标,以空格为间隔:-"); scanf("%d %d",&end.r,&end.c); MazePath(maze, start, end); break; case 'p': if(found) printf("n求解迷宫的结果如下-n"); PrintMaze(maze); else printf("n找不到路径!n"); 名师资料总结 - - -
12、精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 10 页 - - - - - - - - - void main() char cmd; printf(" welcome to the game! "); Initialization(); do ReadCommand(cmd); / 读入一个操作符命令Interpret(cmd); / 解释执行命令操作符while(cmd!='q'); #include "stdio.h" #inclu
13、de "malloc.h" #include"typedef.h" #include"CONSTANT.h" Status InitStack(Stack &S) / 构造一个空栈S S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType); if (!S.base) return OVERFLOW; / 存储分配失败S.top = S.base; S.size = STACK_INIT_SIZE; return OK; /InitStack Status Push(S
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年数据结构迷宫问题源代码 2022 数据结构 迷宫 问题 源代码

限制150内