//迷宫问题,暴力求解
#include"stdio.h"
#include"Stack.c"
#define MAX_SIZE 100 //迷宫最大规格是100x100
int MG[MAX_SIZE][MAX_SIZE] ;//1代表通,0代表不通
typedef struct Mnode {
int up ,down ,left , right ;
int pass ;//是否经过
}Mnode ;
Status Search_Road ( Stack *s , int width , int height ,point start , point end);//寻找路径函数,找到返回TRUE
int main (){
Stack s ;
Stack out;
int w,h ;
int i , j;
point start ;
point end ;
if( Init_Stack(&s)){
printf("Input migong canshu :\n") ;
scanf("%d %d" ,&w , &h) ;
// printf("%d %d \n",w,h);
printf("input road ,0 is not able,1 is not able \n");
for ( i = 0 ; i < w ; i ++){
for ( j = 0 ; j < h ; j++ ){
scanf("%d", &MG[i][j]) ;
}
}
start.x = 1 , start.y =1 ,end.x = w-2,end.y = h-2 ;
if (Search_Road(&s,w,h,start,end)){
Init_Stack(&out) ;
point p;
while (!IsEmpty(&s)){
//point p;
p = Pop(&s) ;
Push(&out,p) ;
}
p = Pop(&out) ;
printf("[%d , %d]",p.x,p.y);
while (!IsEmpty(&out)){
// point p ;
p = Pop(&out) ;
printf("--> [%d , %d]",p.x,p.y);
}
}else{
printf("No Way !\n");
}
}
}
void Clear(Mnode *m){
m->down = 0;
m->left = 0;
m->right = 0;
m->up = 0;
m->pass = 0 ;
}
Status Search_Road ( Stack *s , int width , int height ,point start , point end){
int i = 0 , j = 0 ;
point p = start ;
Mnode m[MAX_SIZE][MAX_SIZE]
栈-迷宫求解路径问题
最新推荐文章于 2022-05-06 17:36:40 发布
本文介绍如何利用栈来解决迷宫求解路径的问题,提供了具体的求解思路和相关代码实现,同时给出了输入测试用例。
摘要由CSDN通过智能技术生成