📄 stack.cpp
字号:
#include "stdafx.h"
#include "stack.h"
#include "mazepath.h"
#define NULL 0
#define RANGE 10 //设置数组的最大长度
typedef int DirectType;
typedef struct {
int r,c; //迷宫中r行c列的位置
}PosType;
typedef struct {
int row,col;
char arr[RANGE][RANGE];//各位置取值' ','#','@'或'*'
}MazeType;
typedef struct {
int step; //当前位置在路径上的“序号”
PosType seat; //当前的坐标位置
DirectType di; //往下一坐标位置的方向
}ElemType; //栈的元素类型
typedef struct NodeType {
ElemType data;
struct NodeType *next;
}NodeType,*LinkType; //结点类型,指针类型
typedef struct {
LinkType top;
int size;
}Stack; //栈类型
void InitStack(Stack &S){
S.top=NULL;
S.size=0;
}
void DestroyStack(Stack &S){
free(S.top);
}//销毁栈S,并释放所占空间
int StackEmpty(Stack S){
if(S.size==0)return 1;
else return 0;
}//若S为空栈(S.top==NULL),则返回1;否则返回0
void Push(Stack &S,ElemType e){
LinkType p;
MakeNode(p,e);
p->next=S.top;
S.top=p;
S.size++;
}//在S的栈顶插入新的栈顶元素e
void Pop(Stack &S,ElemType e){
LinkType p;
if(StackEmpty(S))return;
else {
p=(LinkType)malloc(sizeof(NodeType));
p=S.top;
S.top=S.top->next;
e.step=p->data.step;
e.seat=p->data.seat;
e.di=p->data.di;
S.size--;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -