lxastack.cpp

来自「vc编写的数据结构」· C++ 代码 · 共 58 行

CPP
58
字号
// lxastack.cpp: implementation of the lxastack class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "lxastack.h"

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

lxastack::lxastack(int sz=defaultlistsize)
{
	size=sz;
	top=0;
	listarray=new int[sz];

}

lxastack::~lxastack()
{
	delete [] listarray;

}

void lxastack::clear()
{
	top=0;

}

bool lxastack::push(const int &item)
{
	if(top==size) return false;
	else {listarray[top++]=item;return true;}

}

bool lxastack::pop(int &it)
{
	if(top==0) return false;
	else {it=listarray[--top];return true;}

}

bool lxastack::topvalue(int &it)
{
	if(top==0)return false;
	else{it=listarray[top-1];return true;}

}

int lxastack::length() const
{
	return top;

}

⌨️ 快捷键说明

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