⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.h

📁 一些简单数据结构的实现。 包括了链表、堆、栈等。
💻 H
字号:
/*****************************
*         _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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -