| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:我这个用栈解迷宫程序哪里错了
只看楼主 加入收藏
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
结帖率:29.41%
收藏
已结贴  问题点数:20 回复次数:5 
我这个用栈解迷宫程序哪里错了
#include<stdio.h>
#include<stdlib.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,stack;
typedef struct{
    int x;
    int y;
}iterm;

int judge(pstack st)
{
    if(st->top!=-1)
        return 1;
    else return 0;
}
void pop_stack(pstack S,Lacate *te)
{
       *te=S->La[S->top];
       S->top--;
}
pstack creat_stack()
{
    pstack S;
    S=(pstack)malloc(sizeof(pstack));
      
    S->top=-1;
       return S;
}
void push_stack(pstack S,Lacate te)
{
    S->top++;
    S->La[S->top]=te;
}

void mazepath(int maze[][10],iterm move[],int x0,int y0)
{
    int x,y,d,i,j;
    pstack s;
    Lacate 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;
        if(d<4)
        {
            i=x+move[d].x;j=y+move[d].y;
            
            if(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;
            }
            else
            d++;
        }
    }

}




int main()
{
    int x=0,y=0;
    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,x,y);
}
搜索更多相关主题的帖子: include return 
2013-04-21 22:58
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:20 
mazepath函数里面都是 if(),执行一遍就结束了,不知道你要怎么实现

另外那个 iterm m[4] 你编译通过?


[fly]存在即是合理[/fly]
2013-04-22 07:48
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
收藏
得分:0 
哦,前两个if应改成while,我编译就是main函数不通过
--------------------Configuration: 迷宫递归 - Win32 Debug--------------------
Compiling...
迷宫递归.c
F:\数据结构上机\迷宫递归.c(106) : error C2143: syntax error : missing ';' before 'constant'
F:\数据结构上机\迷宫递归.c(106) : error C2109: subscript requires array or pointer type
F:\数据结构上机\迷宫递归.c(106) : error C2059: syntax error : '{'
F:\数据结构上机\迷宫递归.c(110) : warning C4047: 'function' : 'struct iterm *' differs in levels of indirection from 'const int '
F:\数据结构上机\迷宫递归.c(110) : warning C4024: 'mazapath' : different types for formal and actual parameter 2
执行 cl.exe 时出错.

迷宫递归.obj - 1 error(s), 0 warning(s)

但我另写程序测试iterm[4]是可以通过的,我觉得main函数应该没有错误
2013-04-22 12:49
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
编译不过是因为 你 define m 6

后面又 iterm m[4] ,换个变量名就可以了


[fly]存在即是合理[/fly]
2013-04-22 13:34
飞黄腾达
Rank: 2
等 级:论坛游民
帖 子:46
专家分:27
注 册:2013-3-14
收藏
得分:0 
回复 4楼 azzbcc
多谢
2013-04-25 12:59
C_放飞梦想
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-4-25
收藏
得分:0 
都没有注释噢。好些表示看不懂啊
2013-04-25 20:57
快速回复:我这个用栈解迷宫程序哪里错了
数据加载中...
 
   



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

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