c语言迷宫最完整做法(5页).doc





《c语言迷宫最完整做法(5页).doc》由会员分享,可在线阅读,更多相关《c语言迷宫最完整做法(5页).doc(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-c语言迷宫最完整做法-第 5 页#include#include#include#define stack_init_size 200#define stack_increment 10#define ERROE 0#define TRUE 1#define FALSE 0#define OVERFLOW 0#define OK 1typedef int Status;typedef structint x;int y;PosType;typedef struct int ord;/通道块在路径上的“序号”PosType seat;/通道块在迷宫中的“坐标位置”int di;/从此通道块走向
2、下一通道块的“方向”SElemType;typedef structSElemType *base;SElemType *top;int stacksize;SqStack;int mg2020;/*随机生成迷宫的函数/*为了能够让尽量能通过,将能通过的块和不能通过的块数量比大致为2:1*/void Random()int i,j,k;srand(time(NULL);mg10=mg11=mg1819=0;/将入口、出口设置为“0”即可通过for(j=0;j20;j+)mg0j=mg19j=1;/*设置迷宫外围“不可走”,保证只有一个出口和入口*/for(i=2;i19;i+)mgi0=mgi
3、-119=1;/*设置迷宫外围“不可走”,保证只有一个出口和入口*/for(i=1;i19;i+)for(j=1;j=s.stacksize)s.base=(SElemType *)realloc(s.base,(s.stacksize+stack_increment) *sizeof(SElemType);if(!s.base)exit(OVERFLOW);s.top=s.base+s.stacksize;s.stacksize+=stack_increment;*s.top+=e;return OK;/是否空栈Status StackEmpty(SqStack s)if (s.top=s.
4、base) return OK;return OVERFLOW; /留下不能通过的足迹Status MarkPrint(PosType e) mge.xe.y=3;return OK;/下一步PosType NextPos(PosType &e,int dir)PosType E;switch(dir)case 1:E.x=e.x;/向下 E.y=e.y+1; break;case 2:E.x=e.x+1;/向右 E.y=e.y; break; case 3:E.x=e.x;/向上 E.y=e.y-1; break;case 4:E.x=e.x-1;/向左 E.y=e.y; break;ret
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 迷宫 完整 做法

限制150内