牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

Linked List template class

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%

posted on 2008-01-09 17:26 杨粼波 阅读(123) 评论(0)  编辑 收藏 引用