#pragma once #include "SHQuene.h" #include "SHList.h" template class ListQuene:public SHQuene { 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: SHList list; }; template ListQuene::ListQuene(long length):SHQuene(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(); }