Here is an implementation of a list class. Lists are another way to store data. Lists have very fast inserts and deletes however iterating thru the elements in the list is not as fast as iterating thru a data vector. |
template
class ZList
{
public:
class ListNode;
private:
DWORD m_dwSize;
bool bValid;
ZVector m_Offsets;
public:
T AllocItem()
{
T ret;
ret.Initialize();
push_back(ret);
return ret;
}
DWORD GetSize(){ return size(); }
DWORD size()
{
return m_dwSize;
}
inline bool IsEmpty(){ return m_pHead==NULL;}
class ListNode
{
friend class ZList;
public:
T m_Data;
ListNode* m_pNext;
ListNode* m_pPrev;
public:
inline operator T&()
{
return m_Data;
}
ListNode(T pData) : m_pNext(0), m_pPrev(0) { m_Data = pData; }
ListNode() : m_pNext(0), m_pPrev(0){}
};
class Iterator
{
ListNode* m_pCurrent;
bool m_bFirst;
public:
Iterator(ListNode* pBegin) : m_pCurrent(pBegin), m_bFirst(true) {}
operator T&(){ return m_pCurrent->m_Data;}
ListNode* Next()
{
if(m_bFirst)
{
m_bFirst = false;
return m_pCurrent;
&nb%
class ZList
{
public:
class ListNode;
private:
DWORD m_dwSize;
bool bValid;
ZVector m_Offsets;
public:
T AllocItem()
{
T ret;
ret.Initialize();
push_back(ret);
return ret;
}
DWORD GetSize(){ return size(); }
DWORD size()
{
return m_dwSize;
}
inline bool IsEmpty(){ return m_pHead==NULL;}
class ListNode
{
friend class ZList;
public:
T m_Data;
ListNode* m_pNext;
ListNode* m_pPrev;
public:
inline operator T&()
{
return m_Data;
}
ListNode(T pData) : m_pNext(0), m_pPrev(0) { m_Data = pData; }
ListNode() : m_pNext(0), m_pPrev(0){}
};
class Iterator
{
ListNode* m_pCurrent;
bool m_bFirst;
public:
Iterator(ListNode* pBegin) : m_pCurrent(pBegin), m_bFirst(true) {}
operator T&(){ return m_pCurrent->m_Data;}
ListNode* Next()
{
if(m_bFirst)
{
m_bFirst = false;
return m_pCurrent;
&nb%