Files
envi-code/SourceCode/Code2026/Dimension/ListQuene.h
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

109 lines
1.5 KiB
C++

#pragma once
#include "SHQuene.h"
#include "SHList.h"
template<class T> class ListQuene:public SHQuene<T>
{
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<T> list;
};
template<class T>
ListQuene<T>::ListQuene(long length):SHQuene<T>(length)
{
}
template<class T>
ListQuene<T>::~ListQuene()
{
}
template<class T>
T& ListQuene<T>::operator[](long i)
{
return list[i];
}
template<class T>
bool ListQuene<T>::DeQuene(T&t)
{
if (this->IsEmpty())
{
return false;
}
list.MoveToFirst();
t = list.GetCurData();
list.DelCur();
return true;
}
template<class T>
bool ListQuene<T>::EnQuene(T const&t)
{
if (this->IsLengthLimited() && GetLength() >= this->maxLength)
{
return false;
}
list.AddTail(t);
return true;
}
template<class T>
long ListQuene<T>::GetLength()
{
return list.GetLength();
}
template<class T>
bool ListQuene<T>::GetHeadData(T&t)
{
if (this->IsEmpty())
{
return false;
}
list.MoveToFirst();
t = list.GetCurData();
return true;
}
template<class T>
bool ListQuene<T>::GetTailData(T&t)
{
if (this->IsEmpty())
{
return false;
}
list.MoveToLast();
t = list.GetCurData();
return true;
}
template<class T>
void ListQuene<T>::Clear()
{
list.Clear();
}