stack.h

来自「一些简单数据结构的实现。 包括了链表、堆、栈等。」· C头文件 代码 · 共 112 行

H
112
字号
/*****************************
*         _Stack_h_          *
*           Stack            *
*       class template       *
*       create by si.si      *
*          2007.9.25         *
******************************/

#ifndef _Stack_h_
#define _Stack_h_

#include "DList.h"

//name space sisi's data structure
namespace SSDataS
{
/*
*stack class template
*/
	template<class T>
	class Stack : private DList<T>
	{
	public:
		//constructor and destructor
		Stack();
		~Stack();

		//stack method

		/*func Push : bool 
		*push the new item into this stack
		*@param newItem : T the newItem to push into
		*@return : bool return true if success
		*/
		bool Push(T newItem);

		/*func Pop : bool
		*pop the top item in from this stack
		*@param item : T& the item to return the top
		*            item in this stack
		*@return : bool return true if success
		*/
		bool Pop(T& item);

		/*func getLength : int const
		*get the length of this stack
		*@return : int 
		*/
		int getSLength() const;

		/*
		*func isSEmpty : bool
		*get the EMPTY inf. of this stack
		*@return ; bool return true if empty
		*/
		bool isSEmpty();

		/*
		*func getTopItem : T const
		*get the top item in this stack
		*return : T 
		*/
		T getTopItem() const;
	};

};



using namespace SSDataS;

template<class T>
Stack<T>::Stack()
{
}

template<class T>
Stack<T>::~Stack()
{
}

template<class T>
bool Stack<T>::Push(const T newItem)
{
	return insertAtHead(newItem);
}

template<class T>
bool Stack<T>::Pop(T &item)
{
	return removeFromHead(item);
}

template<class T>
int Stack<T>::getSLength() const
{
	return getLength();
}

template<class T>
bool Stack<T>::isSEmpty()
{
	return isEmpty();
}

template<class T>
T Stack<T>::getTopItem() const
{
	return getHeadData();
}

#endif

⌨️ 快捷键说明

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