File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -48,18 +48,11 @@ class LinkedList {
48
48
49
49
class Iterator {
50
50
ItemType* _node;
51
- ItemType* _nextNode = nullptr ;
52
51
friend class LinkedList ;
53
52
public:
54
- Iterator (ItemType* current = nullptr ) : _node(current) {
55
- _nextNode = _node != nullptr ? _node->next : nullptr ;
56
- }
57
- Iterator (const Iterator& i) : _node(i._node) {
58
- _nextNode = _node != nullptr ? _node->next : nullptr ;
59
- }
53
+ Iterator (ItemType* current = nullptr ) : _node(current) {};
60
54
Iterator& operator ++() {
61
- _node = _nextNode;
62
- _nextNode = _node != nullptr ? _node->next : nullptr ;
55
+ if (_node) _node = _node->next ;
63
56
return *this ;
64
57
}
65
58
bool operator != (const Iterator& i) const { return _node != i._node ; }
@@ -172,7 +165,7 @@ class LinkedList {
172
165
}
173
166
bool remove (const ConstIterator& t, const ConstIterator& where = ConstIterator(nullptr )) {
174
167
if (where._node ) {
175
- if ((where._nextNode ) != t._node ) return false ;
168
+ if ((where._node -> next ) != t._node ) return false ;
176
169
_remove (where._node , t._node );
177
170
return true ;
178
171
}
You can’t perform that action at this time.
0 commit comments