linkedstack.cpp

来自「背包问题的解决」· C++ 代码 · 共 56 行

CPP
56
字号
#include "linkedstack.h"
#include "Node.h"
#include <iostream>

using namespace std;

linkedstack::~linkedstack(){
	Node *next;
	while(top){
		next=top->link;
		delete top;
		top=next;
	}
}

bool linkedstack::isfull()const
{
	try{Node *p=new Node;
		delete p;
		return false;
		}
	catch(...){return true;}
}

int linkedstack::Top()const
{
	if(isempty())cout<<"the stack is empty!"<<endl;
	return top->data;
}

linkedstack &linkedstack::Add(const int &x,int y)
{
	Node *p= new Node;
	p->data=x;
	p->sign=y;
	p->link=top;
	top=p;
	return *this;
}

linkedstack &linkedstack::Delete(int &x)
{
//cout<<"the stack is empty!"<<endl;
	if(!isempty())
	{
		x=top->data;
		Node *p=top;
		top=top->link;
		delete p;
		
	}
	return *this;
}
linkedstack ::last(){
if(!(isempty()))return top->sign;
}

⌨️ 快捷键说明

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