运算符 -- 在链表中
Operator-- in Linked List
我正在尝试重载运算符 - 在单向列表中。
我有一个节点类,其中包含:T 信息节点类型 *链接
迭代器类(它是单链表的朋友):节点类型 *第一个节点类型 *当前布尔关闭边缘
单向链表类,具有:*第一*最后
我已经成功修改了运算符++方法,并且通过了所有测试。代码如下:
if(offTheEdge == true)
{
return *this;
}
else
{
if(current->link == NULL)
{
offTheEdge = true;
return *this;
}
else
{
current = current->link;
}
}
return *this;
我的指示如下:与运算符++相同,但倒退。在单向链表中向后移动意味着你必须从头开始,并确定这个>电流背后的节点。
请帮忙,无论我尝试什么,我都无法获得以前的元素并向后工作。谢谢!
我的运算符代码是:
ListIterator<T> temp;
temp.current = first;
while(temp.current->link != this->current)
{
temp.current = temp.current->link;
}
return temp;
如果我的列表是 2,4,6,8,10,12,14,16,18,20....它每次都返回 20
据我所知,实际的迭代器在您的代码中不会更改。在你的运算符++代码中,你有current = current->link
,但在运算符中,你只改变临时迭代器(即 this->current
实际上从未改变过)。
相关文章:
- 链表中的重载运算符<<
- 重载运算符 += 用于 C++ 中的链表
- 链表的重载运算符+
- 运算符 == 双链表的重载
- 使用运算符+将两个已排序的链表合并到位
- 双链表C++的赋值运算符
- 为什么T是未定义的?我正在尝试实现一个用于双链表的节点类,它不喜欢我使用友元运算符后的T
- 运算符"<<"双链表溢出。C++
- C++ 链表列表运算符[]
- C++ - <<运算符重载,链表 - 地址而不是标准输出
- C++ 使用链表的自定义字符串类中的重载 + 运算符
- C++ 带有链表的重载 += 运算符
- C++中动态分配的单向链表的赋值运算符 (MS Visual Studio 2015)
- 如何在C++中使用 <<= 运算符格式化链表
- 链表的这个别名运算符是否会产生深度复制
- 后缀运算符链表泛型节点迭代器
- 链表的赋值运算符
- 对链表复制构造函数和赋值运算符使用 copy() 方法
- 链表运算符 = 移动分配时,将移动所有元素
- 链表运算符重载问题