//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : ListQuene 模板类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: ListQuene 声明 基于单向链表的队列 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _LISTQUENE_H_ #define _LISTQUENE_H_ #ifndef _QUENE_H_ #include "Quene.h" #endif #ifndef _LIST_H_ #include "List.h" #endif template class ListQuene:public Quene { public: ListQuene(long length = -1); virtual ~ListQuene(); //如quene为空,忽略并返回 false virtual bool DeQuene(T&t); //如果超过maxLength,忽略并返回 false virtual bool EnQuene(T const&t); virtual void Clear(); virtual long GetLength(); virtual bool GetHeadData(T&t); virtual bool GetTailData(T&t); virtual T& operator[](long i); protected: List list; }; template ListQuene::ListQuene(long length):Quene(length) { } template ListQuene::~ListQuene() { } template T& ListQuene::operator[](long i) { return list[i]; } template bool ListQuene::DeQuene(T&t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); list.DelCur(); return true; } template bool ListQuene::EnQuene(T const&t) { if (this->IsLengthLimited() && GetLength() >= this->maxLength) { return false; } list.AddTail(t); return true; } template long ListQuene::GetLength() { return list.GetLength(); } template bool ListQuene::GetHeadData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); return true; } template bool ListQuene::GetTailData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToLast(); t = list.GetCurData(); return true; } template void ListQuene::Clear() { list.Clear(); } #endif