链栈的实现

Node节点类:
#ifndef NODE_H
#define NODE_H

class Node
{
public:
	double value;
	Node* next;
	Node* last;
};

#endif
linkstack.h文件:
/***************************************************************************
*@program: to come true the stack by list 
*@autor: kingduo
*@date: 2015/4/26 First Realse
***************************************************************************/
#ifndef LINKSTACK_H
#define LINKSTACK_H
#include "Node.h"

class LinkStack
{
public:
	LinkStack();
	~LinkStack();
	void Push(double value);
	double Pop();
	void Inject(double value);
	double Eject();
	void Print();
private:
	int count;
	Node* head;
	Node* tail;
};

#endif

linkstack.cpp:
#include "LinkStack.h"
#include <iostream>

using namespace std;

LinkStack::LinkStack()
{
	count = 0;
	head = new Node;
	tail = new Node;
	head->next = tail;
	head->last = NULL;
	tail->next = NULL;
	tail->last = head;
}

LinkStack::~LinkStack()
{
	while(head->next != tail)
	{
		Node* deletenote = head->next;
		head->next = deletenote->next;
		delete deletenote;
	}
	delete tail;
	delete head;
}

void LinkStack::Push(double value)
{
	Node* newnode = new Node;
	newnode->value = value;
	newnode->next = head->next;
	newnode->last = head;
	head->next->last = newnode;
	head->next = newnode;
	++ count;
}

double LinkStack::Pop()
{		
	double num = 0.0f;
	if(head->next == tail)
	{	
		cout<<"The stack is empty!"<<endl;
		return -1;
	}else
	{
		Node* deletenode = head->next;
		num = deletenode->value;
		head->next = deletenode->next;
		deletenode->next->last = head;
		delete deletenode;
		-- count;
	}
	return num;
}

void LinkStack::Inject(double value)
{
	Node* newnode = new Node;
	newnode->value = value;
	newnode->next = tail;
	newnode->last = tail->last;
	tail->last->next =newnode;
	tail->last = newnode;
	++ count;
}

double LinkStack::Eject()
{
	double num = 0.0f;
	if(tail->last == head)
	{
		cout<<"The stack is empty"<<endl;
		return -1;
	}else
	{
		Node* deletenode = tail->last;
		num = deletenode->value;
		tail->last = deletenode->last;
		deletenode->last->next = tail;
		delete deletenode;
		-- count;
	}
	return num;
}

void LinkStack::Print()
{
	Node* loopnode = head->next;
	while(loopnode != tail)
	{
		cout<<loopnode->value<<endl;
		loopnode = loopnode->next;
	}
}


;