我一整天都试图弄明白这一点,因为据我所知,我已经在我的重载+和 - 运算符中编写了代码,我需要弄清楚如何重载[]运算符以便在一个值放在它们内部,它将正确遍历列表并指向信息,例如.. [5] 将它向前移动5,[ - 5]将向后移动,任何帮助都会非常感激,就像我说的那样,似乎我几乎已经在我的+和-...中编写了代码.
typename doublyLinkedList<T>::iterator doublyLinkedList<T>::iterator::operator+(const int amount) const {
doublyLinkedList<T>::iterator tempClone(*this);
tempClone.pastBoundary=false;
T i;
if(amount < 0)
{
return this->operator-(-amount);
}
for(i=0; i < amount; i++)
{
if(tempClone.current->forward == NULL)
{
tempClone.pastBoundary =true;
}else
{
++tempClone;
}
}
if(tempClone.pastBoundary == true)
{
return *this;
}else
{
return tempClone;
}
}
template <typename T>
typename doublyLinkedList<T>::iterator doublyLinkedList<T>::iterator::operator-(const int amount) const {
doublyLinkedList<T>::iterator tempClone(*this);
tempClone.pastBoundary=false;
T i;
if(amount < 0)
{
return this->operator+(-amount);
}
for(i=0; i < …Run Code Online (Sandbox Code Playgroud)