标题:这个迷宫把我弄迷了,哪位大哥大姐指点一下
只看楼主
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
结帖率:29.41%
已结贴  问题点数:10 回复次数:1 
这个迷宫把我弄迷了,哪位大哥大姐指点一下
#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
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:7 
细细看下 void mazepath(int maze[][n+2],iterm move[],int x0,int y0) 这个函数吧

一堆基本的错误

我行我乐
我的博客:
http://blog.yuccn. net
2013-03-30 19:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-402412-1-1.html




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

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