设为首页 加入收藏

TOP

用栈实现的自动走迷宫(一)
2012-11-17 09:27:52 来源: 作者: 【 】 浏览:1273
Tags:实现 自动 迷宫

    [cpp

    sqStack.h

    #include "selemtype.h"

    #define MaxSize 1000

    typedef struct

    {

    SElemType data[MaxSize];

    int top;

    }Stack;

    Status InitStack(Stack &S);

    Status DestroyStack(Stack &S);

    Status StackEmpty(Stack &S);

    Status Push(Stack &S,SElemType &e);

    Status Pop(Stack &S,SElemType &e);

    [cpp] view plaincopy

    sqStack.cpp

    #include "sqstack.h"

    #include<iostream>

    using namespace std;

    Status InitStack(Stack &S)

    {

    S.top = 0 ;

    for( int i = 0 ; i < MaxSize ; i++ )

    {

    S.data[i].di = 0 ;

    S.data[i].ord = 0 ;

    S.data[i].seat.c = 0;

    S.data[i].seat.r = 0;

    }

    return true;

    }

    Status DestroyStack(Stack &S)

    {

    S.top = 0 ;

    return true;

    }

    Status StackEmpty(Stack &S)

    {

    bool judger = false ;

    if(S.top == 0)

    judger = true;

    return judger;

    }

    Status Push(Stack &S,SElemType &e)

    {

    bool judger = false;

    if(S.top < MaxSize)

    {

    S.data[S.top] = e ;

    S.top++;

    judger = true ;

    }

    return judger;

    }

    Status Pop(Stack &S,SElemType &e)

    {

    bool judger = false ;

    if(S.top > 0)

    {

    S.top--;

    e = S.data[S.top] ;

    judger = true ;

    }

    return judger;

    }

    [cpp]

    Mazepath.h

    #define N 15

    #define M 22

    //分割块占总空间比例

    #define V 0.4

    typedef struct ElemType

    {

    int x,y;

    char c;

    }ElemType;

    typedef struct MazeType

    {

    ElemType arr[N][M];

    }MazeType;

    Status Pass(MazeType &MyMaze, PosType CurPos);

    void FootPrint(MazeType &MyMaze, PosType CurPos);

    void MarkPrint(MazeType &MyMaze, PosType CurPos);

    PosType NextPos(PosType CurPos, int Dir);

    Status MazePath(MazeType &maze, PosType start, PosType end);

    [cpp]

    Mazepath.cpp

    /*------------------------------------------------

     

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇划分树详解 结合例题hdu4251 下一篇红黑树的实现(int精简版)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: