⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maze.h

📁 数据结构课程设计:迷宫
💻 H
字号:
struct PosType            //定义迷宫坐标位置的类型
{
	int x;                //行值
	int y;                //列值
};


# define MAXLENGTH 30     //假设迷宫的最大行列数为30(包括外围的墙)
typedef int MazeType[MAXLENGTH][MAXLENGTH];//迷宫数组[行][列]
MazeType m;
int curstep=1;            //当前足迹,初始值为1


struct SElemType          //栈的元素类型
{
	int ord;              //通道块在路径上的“序号”
	PosType seat;         //通道块的坐标
	int di;               //从当前通道块走向下一通道块的方向(0,1,2,3分别表示东,南,西,北)
};


struct SqStack            //定义栈的结构
{
	SElemType *base;
    SElemType *top;
	int stacksize;
};


# include <iostream.h>
# include <malloc.h>
# include <stdlib.h>
# define STACK_INIT_SIZE 10
# define STACKINCREMENT 2
int InitStack(SqStack &S)
{                         //构造一个空栈
	if(!(S.base=(SElemType *)malloc(sizeof(SElemType)*STACK_INIT_SIZE)))
		exit(-1);         //存储分配失败
	S.top=S.base;
	S.stacksize=STACK_INIT_SIZE;
	return 1;
}


int StackEmpty(SqStack &S)
{                         //判断栈是否为空
	if(S.top==S.base)
		return 1;
	else
		return 0;
}


int Push(SqStack &S,SElemType &e)
{                         //元素入栈
	if(S.top-S.base>=S.stacksize)
	{                     //栈满,追加存储空间
		S.base=(SElemType *)realloc(S.base,sizeof(SElemType)*(S.stacksize+STACKINCREMENT));
		if(!S.base)
			exit(-1);     //分配失败
		S.top=S.base+S.stacksize;
		S.stacksize+=STACKINCREMENT;
	}
	*S.top++=e;
	return 1;
}


int Pop(SqStack &S,SElemType &e)
{                         //元素出栈(栈非空)
	if(S.top==S.base)
		return 0;
	e=*(--S.top);
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -