| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:这个迷宫把我弄迷了,哪位大哥大姐指点一下
取消只看楼主 加入收藏
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
结帖率:29.41%
收藏
已结贴  问题点数:10 回复次数:0 
这个迷宫把我弄迷了,哪位大哥大姐指点一下
#include<stdio.h>
#define m 6
#define n 8
#define MAXSIZE 100
typedef struct{
    int x;
    int y;
    int d;
}Lacate;
typedef struct{
    Lacate La[MAXSIZE];
    int top;
}*pstack ;
typedef struct{
    int x;
    int y;
}*iterm;
int judge(pstack *st);
void pop_stack(pstack S,Locate *te);
void push_stack(pstack S,Lacate te);
void mazepath(int maze[][n+2],iterm move[],int x0,int y0);
void detroy(pstack S);
int main()
{
    int a[m+2][n+2]={1,1,1,1,1,1,1,1,1,1,
                     1,0,1,1,1,0,1,1,1,1,
                     1,0,0,0,0,1,1,1,1,1,
                     1,0,1,0,0,0,0,0,1,1,
                     1,0,1,1,1,0,0,1,1,1,
                     1,1,0,0,1,1,0,0,0,1,
                     1,0,1,1,0,0,1,1,0,1,
                     1,1,1,1,1,1,1,1,1,1};
    iterm m[4]={{1,0},{-1,0},{0,1},{0,-1}};
    mazepath(a,m,1,1);
}
int judge(pstack st)
{
    if(st->top!=-1)
        return 1;
    else return 0;
}
void pop_stack(pstack S,Locate *te)
{
       te=S->La[S->top];
       S->top--;
}
pstack creat_stack()
{
    pstack S;
       S=(pstack)malloc(sizeof(pstack));
       if(S)
           S->top=-1;
       return S;
}
void push_stack(pstack S,Lacate te)
{
    S->top++;
    S->La[S->top]=te;
}
void detroy(pstack S)
{
    if(S)
        free(S);
       S=NULL;
       return;
}
void mazepath(int maze[][n+2],iterm move[],int x0,int y0)
{
    int x,y,d,i,j;
    pstack s;
    Locate term;
    x=x0;y=y0;d=-1;
    term.x=x0;term.y=y0;term.d=d;
    s=creat_stack();
   
    push_stack(s,term);
   
   
   
    if(judge(s))
    {
        pop_stack(s,&term);
        x=term.x;y=term.y;d=term.d+1;
        while(d<4)
        {
            i=x+move[d].x;j=y+move[d].y;
            
            while(maze[i][j]!=1)
            {
               
                term.x=x;term.y=y;term.d=d;
                push_stack(s,&term);
                x=i;y=j;
                maze[x][y]=-1;
                if(x==m&&y==n)
                {
                    while(judge(s)
                    {
                        pop_stack(s,&term);
                        printf("(%d,%d)-",term.x,term.y);
                    }
                }
                else d=0;
            }
            d++;
        }
    }
    destroy_stack(s);
}



搜索更多相关主题的帖子: void include 大哥 
2013-03-30 18:30
快速回复:这个迷宫把我弄迷了,哪位大哥大姐指点一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016247 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved