下载此文档

C 实现循环链表.doc


文档分类:行业资料 | 页数:约13页 举报非法文档有奖
1/13
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/13 下载此文档
文档列表 文档介绍
注意:循环链表含有头结点[cpp]viewplaincopyprint?#include <iostream>  using namespace std;  template<class Type>  struct Node  {      Type data;      Node<Type> *next;  };  template<class Type>  class Circlist  {  protected:      int len;//链表中结点个数      Node<Type>* Head; //指向头结点  public:      Circlist();//默认构造函数      Circlist(const Circlist<Type>& otherList);//拷贝构造函数      ~Circlist();      void createListForward();//头插法      void createBackward();//尾插法      void initList();//生成头结点,尾部设置为NULL      bool isEmptyList();      void printList();      int  length();      void destoryList();      void getFirstData(Type& firstItem);      void search(const Type searchItem);      void insertFirst(const Type newItem);      void insertLast(const Type newItem);      void insertBefore(const int pos,const Type newItem);      void insertAfter(const int pos,const Type newItem);      void deleteNode(const Type deleteItem);      void deleteNode(const int pos,Type& deleteItem);      void reverse();      const Circlist<Type>& operator=(const Circlist<Type>&otherList);  };    template<class Type>  Circlist<Type>::Circlist() //初始化时,只有一个头结点,有head指向  {      Head = new Node<Type>;      Head->next = Head;      len =0;  }    template<class Type>  Circlist<Type>::Circlist(const Circlist<Type>&otherList)  {      Head = new Node<Type>;      Head->next = Head;      len =0;      Node<Type>* current = Head;      Node<Type>* otherListCurrent = ->next;//otherListCurrent指向第一个元素      if (->next != )//被拷贝的表不是空表      {          while(otherListCurrent->next!=)//拷贝的目标不为空          {              Node<Type>* newNode = new Node<Type>;              newNode->data = otherListCurrent->data;              newNode->next = current->next;              current->next = newNode;              current=current->next;              otherListCurrent = otherListCurrent->next;              len++;          }          if (otherListCurrent->next==)          {              Node<Typ

C 实现循环链表 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数13
  • 收藏数0 收藏
  • 顶次数0
  • 上传人bjy0415
  • 文件大小77 KB
  • 时间2019-03-16