我创建了一个复制ctor和复制操作符。在他们之间和'擦除(迭代器我)'我设法取消引用指针但我找不到。
square_list erase(iterator i)
template<class list>
void square_list<list>::erase( iterator i )
{
if( i == end() )
return;
linked_list_iterator<list> delIter( i.getNode() );
i++;
i.getHead()->data.erase( delIter );
--_size;
squarify();
}
复制ctor
square_list( square_list & slCopy) {
_size = 0;
for( auto it = slCopy.cbegin(); it != slCopy.cend(); ++it)
{
insert(*it);
}
}
复制操作员
square_list& operator = ( square_list & rhs) {
clear();
for (auto it = rhs.begin(); it != rhs.end(); ++it) {
insert( *it);
}
return *this;
}
linked_list erase(iterator_t i)
template <class list>
void linked_list<list>::erase(iterator_t i)
{
node_ptr_t tmpNode = i.getNode();
if(i.getNode() == _head) {
_head = i.getNode()->next;
}
if(i.getNode() == _tail) {
_tail = i.getNode()->prev;
}
if( i.getNode()->next )
i = iterator_t( i.getNode()->next );
else if( i.getNode()->prev)
i = iterator_t( i.getNode()->prev );
if(tmpNode->prev)
tmpNode->prev->next = tmpNode->next;
else
tmpNode->prev = nullptr;
if(tmpNode->next)
tmpNode->next->prev = tmpNode->prev;
else
tmpNode->prev = nullptr;
delete tmpNode;
--_size;
}