数据结构—迷宫(栈实现版)
来源:互联网 发布:知乎比天涯好吗 编辑:程序博客网 时间:2024/06/06 03:36
//// main.c// reo//// Created by 郭瞾阳 on 14-8-13.// Copyright (c) 2014年 gzy. All rights reserved.//#include< stdio.h>#include< stdlib.h>int a[10][10] = { {0,0,0,0,0,0,0,0,0,0}, {0,1,1,0,1,1,1,0,1,0}, {0,1,1,0,1,1,1,0,1,0}, {0,1,1,1,1,0,0,1,1,0}, //0:边界 1:路 2:通路 -1:死路 {0,1,0,0,0,1,1,1,1,0}, {0,1,1,1,0,1,1,1,1,0}, {0,1,0,1,1,1,0,1,1,0}, {0,1,0,0,0,1,0,0,1,0}, {0,0,1,1,1,1,1,1,1,0}, {0,0,0,0,0,0,0,0,0,0}};typedef struct oo{ int x; int y;}seat;typedef struct hee{ int i; int di; seat xy;}DD;typedef struct pp{ DD t; struct pp*next;}hehe;void fist(hehe**fist){ *fist = (hehe*)malloc(sizeof(hehe)); (*fist)->next = NULL;}void push(hehe*fist,DD d){ hehe* p = (hehe*)malloc(sizeof(hehe)); p->t = d; p->next = fist->next; fist->next = p; printf("%d %d\n",d.xy.y,d.xy.x);}void pop(hehe*fist,DD *d){ hehe*ww = fist->next; *d = fist->next->t; fist->next = ww->next; free(ww);}seat next(seat a,int i){ seat b = a; if(i == 1) b.y++; if(i == 2) b.x++; if(i == 3) b.y--; if(i == 4) b.x--; return b;}int iszore(hehe*fist ){ if(fist->next == NULL) return 1; else return 0;}int pass(seat a_s){ if(a[a_s.x][a_s.y] == 1) return 1; else return 0;}void footprint(seat a_s){ a[a_s.x][a_s.y] = 2;}void makeprint(seat a_s){ a[a_s.x][a_s.y] = -1;}int zoupath(seat go,seat end){ hehe*f ; fist(&f); //printf("%d\n",f); int step = 1; DD e; seat pos = go; do{ if(pass(pos)) { footprint(pos); e.i = step; e.di = 1; e.xy = pos; push(f,e); if(pos.x == end.x&&pos.y ==end.y) { return 1; } pos = next(pos ,1); step++; } else { if(!iszore(f)) { pop(f,&e); printf("%d %d\n",e.xy.y,e.xy.x); while(e.di == 4&&!iszore(f)) { makeprint(e.xy); pop(f,&e); printf("%d %d\n",e.xy.y,e.xy.x); } if(e.di<4) { e.di++; push(f,e); pos = next(e.xy,e.di); } } } }while(!iszore(f)); return 0;}int main(){ seat a,b; a.x =1; a.y =1; b.x = 8; b.y = 8; printf("%d\n",zoupath(a,b)); return 0;}
0 0
- 数据结构—迷宫(栈实现版)
- 【数据结构】用栈实现迷宫
- 数据结构 栈的应用 -- 迷宫的实现
- 【数据结构】栈实现迷宫寻路问题
- C++栈实现数据结构中的迷宫求解
- 【数据结构】走迷宫实现
- 数据结构——栈——迷宫(c++)
- 数据结构例程——迷宫问题(用栈结构)
- 栈的使用-迷宫算法实现代码-摘自数据结构实现java版本(个人笔记整理)
- 数据结构迷宫问题C++实现
- 数据结构-栈/c++/迷宫
- 数据结构-栈应用-迷宫
- 数据结构迷宫升级版
- 数据结构 — 迷宫问题
- 迷宫求解(数据结构)
- 【数据结构】迷宫(递归)
- 数据结构的应用——使用栈实现任意迷宫的求解
- 数据结构和算法设计(迷宫求解问题的栈和队列的实现)
- Monitoring Open and Cached Cursors
- 微信分享接口失效的解决方案(2014年12月底失效的微信接口WeixinJSBridge等)
- 搞了一个按量付费的 ShadowSocks 代理服务,0.6 元每 G, 支持比特币付费
- 单链表逆序(c实现)
- 最近的一些小结
- 数据结构—迷宫(栈实现版)
- 小试Python多线程
- UITextField边框颜色
- 新手学跨域
- 以太网网络变压器和中心抽头的接法
- php扩展xdebug基本使用
- C#6.0的语法<一>
- bzoj [HAOI2008] 糖果传递 贪心
- 安装win8后找不到Ubuntu启动项的解决方法