栈-迷宫求解路径问题

本文介绍如何利用栈来解决迷宫求解路径的问题,提供了具体的求解思路和相关代码实现,同时给出了输入测试用例。
摘要由CSDN通过智能技术生成

//迷宫问题,暴力求解




#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] 
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值