#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAXSIZE 100 //定义栈的最大容量
int visited[10][10]; //全局变量,是一个长度和宽度和迷宫一样的二位整形数组,1代表走过了,0代表没走过
using namespace std;
typedef struct { //坐标定义
int x;
int y;
}PosType;
typedef struct { //栈元素定义,包括坐标和下一步走的方向
PosType seat;
int di;
}SElemType;
typedef struct { //栈的定义
SElemType stack[MAXSIZE];
int top;
}SqList;
typedef struct { //迷宫元素的定义,包括一个二维字符型数组,和它的长和宽
char ma[10][10];
int rows;
int cols;
}MazeType;
void InitS(SqList &S) //栈的初始化
{
S.top=0;
}
void push(SqList &S,SElemType e) //入栈
{
S.top++;
S.stack[S.top]=e;
}
void pop(SqList &S,SElemType &e) //弹栈
{
e=S.stack[S.top];
S.top--;
}
int SEmpty(SqList S) //判栈空
{
return S.top==0;
}
void Init_Maze(MazeType &M,char footprint[][10])//初始化三个二维数组:并且初始化最后显示
{
栈的应用:利用顺序栈求解迷宫问题(改编自严蔚敏算法)
最新推荐文章于 2023-04-13 17:07:17 发布