| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 397 人关注过本帖
标题:请帮忙指导一下下面程序(迷宫问题 运行结果出错啦!)
取消只看楼主 加入收藏
淘气猪猪ke
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2012-10-12
结帖率:0
收藏
 问题点数:0 回复次数:0 
请帮忙指导一下下面程序(迷宫问题 运行结果出错啦!)
#include<iostream>
#include<stack>
#include<list>
using namespace std;

#define Row  10
#define Col  10


typedef struct{
    int row,col;
}Seat;

typedef struct  
{
    Seat se;
    int di;
}ElemType;

void ShowMaze(int Maze[Row][Col])
{
   for(int i=0;i<10;++i)
   {
        for(int j=0;j<10;++j)
        {
            cout<<Maze[i][j]<<" ";
        }
        cout<<endl;
   }
}

Seat NextPos(Seat &Curpos, int di)
{
    //返回当前节点的下一节点
    Seat seat = Curpos;
    switch(di)
    {
    case 1:       //东
        seat.col++;
        break;
    case 2:        //南
        seat.row++;
        break;
    case 3:        //西
        seat.col--;
        break;
    case 4:        //北
        seat.row--;
        break;
    }
    return seat;     
}

void FootPrint(int Maze[Row][Col],Seat CurPos)
{
    Maze[CurPos.row][CurPos.col]=2;
}

bool Pass(int Maze[Row][Col],Seat CurPos)
{
    if (Maze[CurPos.row][CurPos.col]==0)
    {
        return true;
    }
    else return false;
}

void MarkPrint(int Maze[Row][Col],Seat seat)
{
    Maze[seat.row][seat.col]=3;
}
bool MazePath(int Maze[Row][Col],Seat start,Seat end)
{
    Seat CurPos = start;
    ElemType e;
    stack<ElemType>  st;
    do
    {
        if (Pass(Maze,CurPos))
        {
            e.se=CurPos;
            e.di=1;        
            st.push(e);
            FootPrint(Maze,CurPos);
            if ((CurPos.row==end.row)&&(CurPos.col==end.col))
            {
                return true;
            }
            else
            {
                CurPos=NextPos(CurPos,e.di);
            }
        }
        else
        {
            if (!st.empty())
            {   
                e=st.top ();
                st.pop();
                while((e.di==4)&&(!st.empty()))
                {
                    MarkPrint(Maze,e.se);
                    e= st.top();               
                    st.pop (); //退回一步            
                }
                if(e.di<4)
                {
                    e.di++;
                    st.push(e);
                    CurPos=NextPos(e.se,e.di);
                }
            }
        }
        
    } while (!st.empty());
    return false;
}

void main()
{
    Seat start={1,0};
    Seat end={8,9};
    int Maze[Row][Col]={
        {1,1,1,1,1,1,1,1,1,1},
        {0,0,0,0,0,0,1,1,1,1},
        {1,0,1,1,1,0,0,1,1,1},
        {1,0,0,1,1,0,1,1,1,1},
        {1,1,0,0,0,1,1,1,1,1},
        {1,0,0,1,0,0,0,0,0,1},
        {1,0,1,0,0,1,1,1,1,1},
        {1,0,1,0,1,1,0,0,0,1},
        {1,0,1,0,0,0,0,1,0,1},
        {1,1,1,1,1,1,1,1,0,1}};
        ShowMaze(Maze);
        MazePath(Maze,start,end);
        cout<<endl;
        ShowMaze(Maze);
        
}
搜索更多相关主题的帖子: namespace include 
2013-03-14 12:12
快速回复:请帮忙指导一下下面程序(迷宫问题 运行结果出错啦!)
数据加载中...
 
   



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

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