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

📄 stack.cpp

📁 一个迷宫求解的完整程序
💻 CPP
字号:
// stack.cpp: implementation of the stack class.
//
//////////////////////////////////////////////////////////////////////

#include "stack.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

stack::stack()
{
   InitStack();
}

stack::~stack()
{
   DestroyStack();
}
///////////////////////////////////////////////////////////////////
Status stack::pop(RoadNode &e)
{//弹出栈顶元素
	if(top==0)
		return  ERROR;
	--top;
	e=base[top];
	return OK;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Status stack::push(RoadNode &e)
{//将元素e压入栈
	if(top==size-1)
	{
		RoadNode *b=(RoadNode*)realloc(base,(INIT_SIZE+INCREMENT)*sizeof(RoadNode));
		if(!b) return ERROR;
		base=b;
		size+=INCREMENT;
	}
	base[top]=e;
	top++;
	return OK;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bool stack::empty()
{//判断栈是否为空,如果为空,返回真,否则返回假
	if(top==0)
		return true;
	else return  false;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Status stack::InitStack()
{//建立一个栈,并初始化
	base=(RoadNode*)malloc(INIT_SIZE*sizeof(RoadNode));
 	if(!base)  return  ERROR;
	top=0;
	size=0;
	return OK;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Status stack::DestroyStack() 
{//销毁栈
	if(base)
		free(base);
	return OK;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void  stack::Display(Labyrinth &L)
{
	cout<<"the stack is:\n";
	for(int i=0;i<top;i++)
		cout<<"("<<base[i].x<<","<<base[i].y<<")"<<" ";		
	cout<<"\n";
}

⌨️ 快捷键说明

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