数据结构迷宫问题
以下程序只是一个路径:
Status MazePath(MazeType &maze,PosType start, PosType end){
//求解迷宫maze中,从入口start到出口end的一条路径
//若存在,返回TRUE,否则返回FALSE
SqStack s;SElemType e;
InitStack(s);
PosType curpos = start;
int curstep = 1; //探索第一部
do{
if( Pass(maze,curpos) ){ //如果当前位置可以通过,即是未曾走到的通道块
FootPrint(maze,curpos); //留下足迹
e = CreateSElem(curstep,curpos,1); //创建元素
Push(s,e);
if( PosEquare(curpos,end) ) return TRUE;
curpos =NextPos(curpos,1); //获得下一节点:当前位置的东邻
curstep++; //探索下一步
}else{ //当前位置不能通过
if(!StackEmpty(s)){
Pop(s,e);
while(e.di==4 && !StackEmpty(s) ){
MarkPrint(maze,e.seat); Pop(s,e);curstep--; //留下不能通过的标记,并退回一步
}
if(e.di<4){
e.di++; Push(s,e); //换一个方向探索
curpos = NextPos(e.seat,e.di); //求下一个节点
}
}
}
}while(!StackEmpty(s));
return FALSE;
}
相关推荐
数据结构实验迷宫问题实验报告
数据结构实验迷宫问题实验报告
数据结构迷宫问题实验报告
关于数据结构C的 严蔚敏般的 大二时做实验的 希望对你有帮助
C语言数据结构迷宫问题
//------------ 栈的顺序存储实现 ------------------------------typedef struct...{ int row; int col;}PosType;typedef struct...{ int step; //当前位置在路径上的"序号" PosType seat; //当前的坐标位置 DirectiveType 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;}
C语言数据结构之迷宫问题
本文实例为大家分享了数据结构c语言版迷宫问题栈实现的具体代码,供大家参考,具体内容如下 程序主要参考自严蔚敏老师的数据结构c语言版,在书中程序的大体框架下进行了完善。关于迷宫问题的思路可查阅原书。 #include<iostream> using namespace std; #define MAXSIZE 10 typedef int Status; typedef struct{ int x; int y; }Postype; typedef struct{ int ord; Postype seat; int dir; }SElemType;//栈的元素类型 typedef
迷宫问题 数据结构
用C语言编写的用栈和队列两种线性结构程序,解决迷宫问题



