文档介绍:[首页,上一页,下一页;  目录]第二章单链表链表是最常用、最简单和最基本的数据结构之一。我们先来看看单链表的实现。  代码实现单链表的实现如下:///////////////////////////////////////////////////////////////////////////////////FileName://Version://Author:LuoCong//Date:2004-12-299:58:38//Comment://///////////////////////////////////////////////////////////////////////////////#ifndef__SINGLE_LIST_H__#define__SINGLE_LIST_H__#include<>#include<>#ifdef_DEBUG#defineDEBUG_NEWnew(_NORMAL_BLOCK,THIS_FILE,__LINE__)#endif#ifdef_DEBUG#definenewDEBUG_NEW#harTHIS_FILE[]=__FILE__;#endif#ifdef_DEBUG#ifndefASSERT#defineASSERTassert#endif#else//not_DEBUG#ifndefASSERT#defineASSERT#endif#endif//_DEBUGtemplate<typenameT>ode{public:ode<T>*ode():data(T()),next(NULL){}CNode(constT&initdata):data(initdata),next(NULL){}CNode(constT&ode<T>*p):data(initdata),next(p){}};template<typenameT>classCSList{protected:ode<T>*m_pNodeHead;public:CSList();CSList(constT&initdata);~CSList();public:intIsEmpty()const;intGetCount()const;intInsertBefore(constintpos,constTdata);intInsertAfter(constintpos,constTdata);intAddHead(constTdata);intAddTail(constTdata);voidRemoveAt(constintpos);voidRemoveHead();voidRemoveTail();voidRemoveAll();T&GetTail();TGetTail()const;T&GetHead();TGetHead()const;T&GetAt(constintpos);TGetAt(constintpos)const;voidSetAt(constintpos,Tdata);intFind(constTdata)const;};template<typenameT>inlineCSList<T>::CSList():m_nCount(0),m_pNodeHead(NULL){}template<typenameT>inlineCSList<T>::CSList(constT&initdata):m_nCount(0),m_pNodeHead(NULL){AddHead(initdata);}template<typenameT>inlineCSList<T>::~CSList(){RemoveAll();}template<typenameT>inlineintCSList<T>::IsEmpty()const{return0==m_nCount;}template<typenameT>inlineintCSList<T>::AddHead(constTdata){CNode<T>*pNewNode;pNewNode=ode<T>;if(NULL==pNewNode)return0;pNewNode->data=data;pNewNode->next=m_pNodeHead;m_pNodeHead=pNewNode;++m_nCount;return1;}template<typenameT>inlineintCSList<T>::AddTail(constTdata){returnInsertAfter(GetCount(),data);}//ess,returnthepositionofthenewnode.//iffail,