queue.h

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

H
127
字号
/*****************************
*         _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 + =
减小字号Ctrl + -
显示快捷键?