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

128 lines
2.1 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// 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 T> class ListQuene:public Quene<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:
List<T> list;
};
template<class T>
ListQuene<T>::ListQuene(long length):Quene<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();
}
#endif