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

📄 queue.h

📁 一些简单数据结构的实现。 包括了链表、堆、栈等。
💻 H
字号:
/*****************************
*         _Queue_h_          *
*           Queue            *
*       class template       *
*       create by si.si      *
*          2007.10.3         *
******************************/

#ifndef _Queue_h_
#define _Queue_h_

#include "DList.h"

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

		//Queue method
		/*
		*func In : bool
		*add a new item into this queue
		*@param newItem : T the new item 
		*@return : bool return true if success
		*/
		bool In(const T newItem);
		
		/*
		*func Out : bool
		*let the first item out of queue
		*@param outItem : T&  return the out item
		*return : bool return true if success
		*/
		bool Out(T& outItem);


		/*
		*func getQLength : int const
		*get the length of this queue
		*@return : int the length of this queue
		*/
		int getQLength() const;

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

		/*
		*func getFirstItem : T const
		*get the first item in this queue
		*@return : T the first item
		*/
		T getFirstItem() const;

		/*
		*func getLastItem : T const
		*get the last item in this queue
		*@return : T the last item
		*/
		T getLastItem() const;

	};
};



using namespace SSDataS;

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

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

template<class T>
int Queue<T>::getQLength() const
{
	return getLength();
}

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

template<class T>
bool Queue<T>::Out(T &outItem)
{
	return removeFromTail(outItem);
}

template<class T>
bool Queue<T>::isQEmpty()
{
	return isEmpty();
}

template<class T>
T Queue<T>::getFirstItem() const
{
	return getTailData();
}

template<class T>
T Queue<T>::getLastItem() const
{
	return getHeadData();
}

#endif

⌨️ 快捷键说明

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