lxlstack.cpp

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

CPP
67
字号
// lxlstack.cpp: implementation of the lxlstack class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "lxlstack.h"

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

lxlstack::lxlstack(int sz=defaultlistsize)
{
	top=NULL;size=0;

}

lxlstack::~lxlstack()
{
	clear();

}

void lxlstack::clear()
{
	while(top!=NULL){
		lxlink* temp=top;
		top=top->next;
		delete temp;
	}
	size=0;
}

bool lxlstack::push(const int &item)
{
	top=new lxlink(item,top);
	size++;
	return 0;

}

bool lxlstack::pop(int &it)
{
	if(size==0)return false;
	it=top->element;
	lxlink* ltemp=top->next;
	delete top;
	top=ltemp;
	size--;
	return true;

}

bool lxlstack::topvalue(int &it) const
{
	if(size==0) return false;
	it=top->element;
	return true;

}

int lxlstack::length() const
{
	return size;

}

⌨️ 快捷键说明

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