- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
栈的经典应用——迷宫问题
#includestring.h#includectype.h#includemalloc.h #includelimits.h#includestdio.h#includestdafx.h#includestdlib.h #includeio.h#includemath.h #includeprocess.h #define TRUE 1#define FALSE 0#define ok 1#define error 0#define overflow -2#define INFEASIBLE -1#define maxlength 25#define INIT_STACK_SIZE 100#define STACKINCREMENT 10 typedef int status;int curstep=1;typedef struct{?int x;?int y;}position;//这地方 不解释typedef int mgsz[maxlength][maxlength];mgsz m;typedef struct{?int number;?position seat;?int direction;}SElemtype;//栈里面存放元素的类型typedef struct//这里面的数据的类型要注意一下,好简单的问题,去问{?SElemtype *top;?SElemtype *base;?int stacksize;}sqstack;//栈的基本结构status InitStack(sqstack *s){?s-base=(SElemtype *)malloc(INIT_STACK_SIZE*sizeof(SElemtype));?if(!s-base)??exit(overflow);?s-stacksize=INIT_STACK_SIZE;?s-base=s-top;?return ok;}status DeleteStackTop(sqstack *s,SElemtype *e){?if(s-base==s-top)??return error;?*e=*(s-top-1);?s-top=s-top-1;?return ok;}status GetStackTop(sqstack s,SElemtype *e){?if(s.base=s.top)??return error;?else??*e=*(s.top-1);?return ok;}status StackEmpty(sqstack s){?if(s.base==s.top)??return TRUE;?else??return FALSE;}status InsertStack(sqstack *s,SElemtype e){?SElemtype *newbase;?SElemtype a;?newbase=a;?if(s-top-s-base=s-stacksize)?{??newbase=(SElemtype*) realloc(s-base,(s-stacksize+STACKINCREMENT)*sizeof(SElemtype));//为什么总是犯这些小错误,就是因为*,你调试大半天!!靠??if(!newbase)???exit(overflow);??s-base=newbase;??s-top=s-base+s-stacksize;??s-stacksize=s-stacksize+STACKINCREMENT;??return ok;?}}status pass(position b)//为1时,通过{?if(m[b.x][b.y]==1)??return ok;?else ??return error;}void footprint(position a)//打印出当前的路径{?m[a.x][a.y]=curstep;}position nextposition(position c,int i)//返回下一个通道{?position fangxiang[4]={{0,1},{1,0},{0,-1},{-1,0}};//表示东南西北四个方向?c.x=c.x+fangxiang[i].x;?c.y=c.y+fangxiang[i].y;?return c;}void dispassprintmark(position b)//不能通过改成-1{?m[b.x][b.y]=-1;}status FindRoadPath(po
文档评论(0)