堆栈求迷宫问题
来源:互联网 发布:vb 判断文件是否存在 编辑:程序博客网 时间:2024/06/08 06:18
堆栈求迷宫问题
/*Name: 堆栈求迷宫问题 Copyright: Author: Date: 14/04/17 18:25Description: 希望以后参考到*/#include<iostream>using namespace std;typedef struct {int i;int j;int di;}box;typedef struct{box data[50];int top;}road;int mg[5][5]={{1,1,1,1,1},{1,0,1,1,1},{1,0,1,0,1},{1,1,1,0,1},{1,1,1,1,1}};void mapath(int xi,int yi,int m,int n){road s;int x,y,k;int find;int di;s.top=-1;s.top++;s.data[s.top].i=xi;s.data[s.top].j=yi;s.data[s.top].di=-1;mg[xi][yi]=-1;while(s.top>-1){x=s.data[s.top].i;y=s.data[s.top].j;di=s.data[s.top].di;if(x==m&&y==n){cout<<"路径如下:"<<endl; for(k=0;k<=s.top;k++)cout<<s.data[k].i<< s.data[k].j<<endl;}find=0;while(di<4&&find==0){di++;switch(di){case 0: x=s.data[s.top].i;y=s.data[s.top].j-1;break;case 1: x=s.data[s.top].i+1;y=s.data[s.top].j;break;case 2: x=s.data[s.top].i;y=s.data[s.top].j+1;break;case 3: x=s.data[s.top].i-1;y=s.data[s.top].j;break;}if(mg[x][y]==0)find=1;}if(find==1) //找到下一个可走方块 {s.data[s.top].di=di;s.top++;s.data[s.top].i=x;s.data[s.top].j=y;s.data[s.top].di=-1;mg[x][y]=-1;}else //没有路径可走,则推栈 {mg[s.data[s.top].i][s.data[s.top].j]=0;s.top--;}}cout<<"没有可走的路径"; }int main(){mapath(1,1,3,3);return 0;}
阅读全文
0 0
- 堆栈求迷宫问题
- 堆栈解决迷宫搜索问题
- DFS求迷宫问题
- 求迷宫通路问题
- 队列求迷宫问题
- 迷宫问题(堆栈及其应用)
- 利用堆栈实现迷宫问题的求解
- 回溯法求迷宫问题
- 回溯法求迷宫问题
- 回溯法求迷宫问题
- 迷宫问题求最小路径
- poj 3984 迷宫问题 dfs 求迷宫路径
- 迷宫问题中的链式堆栈类的实现
- 迷宫求解问题——堆栈的使用
- 算法:堆栈与深度优先搜索(迷宫问题)
- 算法:堆栈与深度优先搜索(迷宫问题)
- 深度优先搜索(堆栈)解决走迷宫问题
- 迷宫问题——堆栈应用(C++版)
- 获取form内iframe中的textarea(kindeditor)的值
- caffe 网络结构参数介绍及可视化
- volatile关键字
- 算法--06谷歌面试:字符串中第一个只出现一次的字符(Java实现)
- 一、STL模板
- 堆栈求迷宫问题
- 如何分析帐号异常?看这里!
- windbg中所谓的上下文
- bzoj 3689: 异或之 字典树+堆
- sublime text3插件安装-第一周
- webdriver启动浏览器问题
- 学习历程
- meta标签中的http-equiv属性使用介绍
- CS Academy Round #33 Subinterval Division