网站大量收购闲置独家精品文档,联系QQ:2885784924

数据结构-迷宫解算法.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构-迷宫解算法

#include stdio.h #include stdlib.h #define overflow -1 #define ok 1 #define error 0 #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int Status; typedef struct { int x; int y; }PosType;//位置类型 typedef struct { int row,col; int a[50][50]; }MazeType;//迷宫类型 typedef struct { int ord;//通道块在路径上的序号 PosType seat;//通道块在迷宫中的“坐标位置” int di;//从此通道块走向下一个通道块的方向 }SElemType;//栈的元素类型 typedef struct { SElemType *base; SElemType *top; int Stacksize; }SqStack;//栈结构 Status InitStack(SqStack S)//初始化栈 { S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!S.base) exit (overflow); S.top=S.base; S.Stacksize=STACK_INIT_SIZE; return ok; } Status Push(SqStack S,SElemType e)//入栈 { if(S.top-S.base=S.Stacksize) { S.base=(SElemType *)realloc(S.base,(S.Stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S.base) exit (overflow); S.top=S.base+S.Stacksize; S.Stacksize+=STACKINCREMENT; } *S.top++=e; return ok; } Status Pop(SqStack S,SElemType e)//出栈 { if(S.top==S.base) return error; e=*--S.top; return ok; } bool StackEmpty(SqStack S)//判断栈是否为空 { if(S.top==S.base) return ok; else return error; } Status InitMaze(MazeType maze)//初始化迷宫 { int i,j; for( j=0;jmaze.col+2;j++) maze.a[0][j]=1; for( i=1;imaze.row+1;i++) { maze.a[i][0]=1; maze.a[i][maze.col+1]=1; for(int j=1;jmaze.col+1;j++) scanf(%d,maze.a[i][j]); } for(j=0;jmaze.col+2;j++) maze.a[maze.row+1][j]=1; return ok; }//为了避免检查边界,把迷宫的外围都设成障碍,迷宫的内核是row行,col列的数组 bool Pass(MazeType maze,PosType curpos)//判断是否可以通过 { return maze.a[curpos.x][curpos.y]==0; } Status FootPrint(MazeType maze,PosType curpos)//留下足迹 { maze.a[curpos.x][curpos.y]=2; return ok; } SElemType CreatElem(int step,PosType pos,int di)//创造一个SElemType型的数据 { SElemType e; e.ord=step; e.seat=pos; e.di=di; return e; } bool IsEnd(PosType pos1,PosType pos2)//判断是否结束 { return pos1.x==pos2.xpos1.y==pos2.y; } PosType NextPos(PosType curpos,int

文档评论(0)

guf825 + 关注
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档