博文
带头结点的双循环链表(2009-04-03 10:15:00)
摘要:struct DouCirListNode{ int data; DouCirListNode *prior, *next;
public: DouCirListNode():prior(NULL),next(NULL){} DouCirListNode(int elem, DouCirListNode *first=NULL,DouCirListNode *back=NULL):data(elem),prior(first),next(back){} ~DouCirListNode(){prior=NULL; next=NULL;}};
class DouCirList{private: DouCirListNode *first;public: DouCirList():first(new DouCirListNode()){ first->prior=first; first->next=first; } ~DouCirList(){ MakeEmpty(); delete first; } bool MakeEmpty(); int ListLength(); bool IsEmpty(); DouCirListNode* Find(int location); DouCirListNode* FindData(int elem); bool Insert(int location, int elem); void Remove(int location); bool RemoveAll(int elem); int GetData(int location); void ShowList();};
bool DouCirList::MakeEmpty(){ DouCirListNode *ptem=first->next, *pdel; while(ptem......
单循环链表--实现(2009-04-01 22:21:00)
摘要:#include<iostream>using namespace std;
template<class Type> class CircularList;
template<class Type> class CircListNode{private: friend class CircularList<Type>; CircListNode():link(NULL){} CircListNode(const Type item,CircListNode<Type> *next=NULL):m_data(item),link(next){} ~CircListNode(){ link=NULL; } private: Type m_data; CircListNode *link;};template<class Type> class CircularList{public: CircularList():first(new CircListNode<Type>()){ first->link=first; } ~CircularList(){ MakeEmpty(); delete first; }public: void MakeEmpty(); //clear the list int Length(); //get the length CircListNode<Type> *Find(Type value,int n); //find the nth data which is equal to value CircListNode<Type> *Find(int n); //find the nth data bool Insert(Type item,int n=0);  ......
