background image

 

非模板类 CObList    CPtrList    CStringList 

MFC

——

链表类的常用成员函数

以 Clist 为例 

1.CList

 

( int nBlockSize = 10 );

2.TYPE GetHead

   

( ) const;

3.TYPE GetTail

 

() const;

4.RemoveHead()

5.RemoveTail()

6.原型 1:POSITION AddHead

 

( ARG_TYPE newElement );

原型 2:void AddHead  

( CList* pNewList );

7.原型 1:POSITION AddTail

 

( ARG_TYPE newElement );

原型 2:void AddTail  

( CList* pNewList );

8.RemoveAll()

9.POSITION GetHeadPosition

   

( ) const;

10.POSITION GetTailPosition

   

( ) const;

11.TYPE GetNext

 

( POSITION& rPosition   

) const;

12.TYPE GetPrev

 

( POSITION& rPosition   

) const;

13.TYPE GetAt

 

( POSITION position   

) const;

14.void SetAt

 

( POSITION pos, ARG_TYPE newElement );

15.void RemoveAt

 

( POSITION position );

16.POSITION InsertBefore

 

( POSITION position, ARG_TYPE newElement );

17.POSITION InsertAfter

 

( POSITION position, ARG_TYPE newElement );

18.POSITION Find

 

( ARG_TYPE searchValue, POSITION startAfter = NULL  

) const; 

19.POSITION FindIndex

 

( int nIndex   

) const;

20.int GetCount

 

() const;

21.BOOL IsEmpty

   

( ) const;

例题

struct CStudent

{

       CString m_strName;

       int m_nScore;

};

CPtrList m_List;

向添加链表中添加元素

CStudent* m_pStudent = new CStudent;

m_pStudent->m_strName = m_strName;

m_pStudent->m_nScore = m_nScore;

m_List.AddTail(m_pStudent);
删除节点

         int nNumber;

CStudent* m_pStudent = NULL;

if (m_List.IsEmpty())

MessageBox("结点已经全部删除!"

;