42.2单链表类的定义和实现 Linlist,h DS template <class T>class linlist private 计算机学院信息教研 Listnode<T>*head;∥指向头结点的指针 int size: ∥单链表的元素个数 Listnode<T>* currEtn;/当前结点指针 public LinList(void) ∥构造函数 vLinList( void) ∥/析构函数 室
template<class T>class LinList { private: ListNode<T> *head; //指向头结点的指针 int size; //单链表的元素个数 ListNode<T> *currPtr; //当前结点指针 public: LinList(void); //构造函数 ~LinList(void); //析构函数 … } 计 算 机 学 院 信 息 教 研 室 DS 4.2.2 单链表类的定义和实现 Linlist.h
4.2.2单链表类的定义和实现 Linlist h DS template<class T>class LinList private 计算机 public. int listsize(void) const//返回链表的元素个数 表 int ListEmpty (void) constr ListNode<T>*ndex( (Int pos)1定位 的 息 void Insert(( const T& item, int pos);//插入 员 T Delete(int pos 教 /删除 研数 T GetData(int pos); //取元素 室 void clearlList(void) F∥/清空链表
template<class T>class LinList { private: public: … int ListSize(void) const;//返回链表的元素个数 int ListEmpty(void) const; ListNode<T> *Index(int pos); //定位 void Insert(const T& item,int pos); //插入 T Delete(int pos); //删除 T GetData(int pos); //取元素 void ClearList(void); //清空链表 … } 计 算 机 学 院 信 息 教 研 室 DS 4.2.2 单链表类的定义和实现 Linlist.h 表 操 作 的 成 员 函 数
4.2.2单链表类的定义和实现 Linlist h DS template<class T>class LinList private 遍历表的函数 public. 算机学院信 ListNode<T>* Reset( int pos=0)∥/把第 pos个结点设置为当前结点 curretn 自 ListNode<T>米Next(void)// currEtn指向 教个结点 int Endoflist(void)cons;// currEtn是否 研指在链表尾 室了
template<class T>class LinList { private: public: … ListNode<T> *Reset(int pos=0); //把第 pos个结点设置为当前结点currPtr ListNode<T> *Next(void); //currPtr指向 下一个结点 int EndOfList(void) const; //currPtr是否 指在链表尾 } 计 算 机 学 院 信 息 教 研 室 DS 4.2.2 单链表类的定义和实现 Linlist.h 遍历表的函数
422单链表类的定义和实现 Linlist. cpp DS head 算 template<assT 机 Insists<T>:! Insist()∥构造函数 院 head= new ListNode<T>Or 自 size =0 教 研 室
template<class T> LinList<T>::LinList() //构造函数 { head = new ListNode<T>(); size = 0; } 计 算 机 学 院 信 息 教 研 室 DS 4.2.2 单链表类的定义和实现 Linlist.cpp head ^
422单链表类的定义和实现 Linlist. cpp DS template<class T> Insist<T>: Insist(void)/析构函数 计算机学院信息教研 ClearList();∥放所有非头结点 delete head;∥/释放头结点 head E nulli head a an/∧ 室he
template<class T> LinList<T>::~LinList(void) //析构函数 { ClearList(); //释放所有非头结点 delete head; //释放头结点 head = NULL; } 计 算 机 学 院 信 息 教 研 室 DS 4.2.2 单链表类的定义和实现 Linlist.cpp a0 a1 … an ^ head head ^