鱼C论坛

 找回密码
 立即注册
查看: 4633|回复: 8

[已解决]c++ 链表旋转

[复制链接]
发表于 2021-9-27 18:00:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问这题目啥意思
循环链表吗还是双向循环之类的
最佳答案
2021-9-27 21:03:07
万千只cnm 发表于 2021-9-27 20:29
他 不是说p往前指向第一个节点吗

是从当前位置一直向前(向头结点)
这个 theChain 是一个双向链表,可以从某一个节点,向前和向后两个方向遍历元素
1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-27 18:04:54 | 显示全部楼层
23 题是什么?
是不是和这个 24 题有关系?
这确实给的内容太少了,很多东西都得猜
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-27 18:05:56 | 显示全部楼层
没有 theChain 这个变量的类型?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-27 18:55:24 | 显示全部楼层
23题是这个
2.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-27 18:56:36 | 显示全部楼层
人造人 发表于 2021-9-27 18:05
没有 theChain 这个变量的类型?

chain是个自定义的类
  1. template<class T>
  2. struct chainNode{//结构体也能构造 成员,函数
  3.      T element;
  4.      chainNode<T> *next;

  5.      chainNode(){}
  6.       chainNode(const T& element){ this->element= element;}
  7.       chainNode(const T& element,chainNode<T> * next){
  8.            this->element= element;
  9.            this->next=next;
  10.       }
  11. };
  12. template<class T>
  13. class chain : public linearList<T>{//抽象类的派生类
  14.     public:
  15.       chain(int init =10);
  16.       chain(const chain<T>&);
  17.       ~chain();

  18.        bool empty() const {return listSize == 0;}//1
  19.         int size() const {return listSize ;} //1
  20.          T& get(int theIndex) const;//返回索引的元素
  21.          int indexOF(const T& theElment) const;//第一次出现的索引
  22.          void erase(int theIndex);
  23.         void insert(int theIndex,const T& theElement);
  24.         void output(ostream & out) const;
  25.         void swap(chain<T>& theChain);//交换两个链表
  26. //      /////习题
  27.         void setSize(int theSize);//若多于 则删除  1
  28.         void set(int theIndex,T theElement);//置换索引元素
  29.         int lastIndexOf(T theElement);//元素最后出现索引
  30.         void removeRange(int fromIndex,int toIndex);//删除索引范围内的所有节点

  31.         T& operator[](int index);
  32.         bool operator==(chain<T> & x);
  33.         bool operator!=(chain<T>& x);
  34.         bool operator<(chain<T>& x);
  35.         void leftShift(int i);//左移动元素 (删除—)
  36.         void reverse();//颠倒元素顺序
  37.         void meld(chain<T>& a,chain<T>& b);//交替合并
  38.         void clean();//清空
  39.         void merge(chain<T>& a,chain<T>& b);//有序合并
  40.         void split(chain<T>& a,chain<T>& b);//分奇偶索引
  41.         void circularShift(int i);//向左循环索引
  42.         void insertSort();//链表排序

  43. ///////////////
  44.       friend ostream& operator<<(ostream& out,const chain<T>& x){ x.output(out); return out;}
  45.         protected:
  46.           void checkIndex(int theIndex) const;
  47.           chainNode<T>* firstNode;
  48.           int listSize;
  49. };
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-27 19:47:00 | 显示全部楼层
对于这个题目,双向链表就可以了
不需要双向循环链表
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-27 19:49:01 | 显示全部楼层
到最后一个节点的时候
l 指向最后一个节点
p = NULL
就可以了
不需要循环
题目也没要求循环
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-27 20:29:38 | 显示全部楼层
人造人 发表于 2021-9-27 19:49
到最后一个节点的时候
l 指向最后一个节点
p = NULL

他 不是说p往前指向第一个节点吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-27 21:03:07 | 显示全部楼层    本楼为最佳答案   
万千只cnm 发表于 2021-9-27 20:29
他 不是说p往前指向第一个节点吗

是从当前位置一直向前(向头结点)
这个 theChain 是一个双向链表,可以从某一个节点,向前和向后两个方向遍历元素
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-7 16:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表