File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -47,10 +47,19 @@ class LinkedList {
47
47
48
48
class Iterator {
49
49
ItemType* _node;
50
+ ItemType* _nextNode = nullptr ;
50
51
public:
51
- Iterator (ItemType* current = nullptr ) : _node(current) {}
52
- Iterator (const Iterator& i) : _node(i._node) {}
53
- Iterator& operator ++() { _node = _node->next ; return *this ; }
52
+ Iterator (ItemType* current = nullptr ) : _node(current) {
53
+ _nextNode = _node != nullptr ? _node->next : nullptr ;
54
+ }
55
+ Iterator (const Iterator& i) : _node(i._node) {
56
+ _nextNode = _node != nullptr ? _node->next : nullptr ;
57
+ }
58
+ Iterator& operator ++() {
59
+ _node = _nextNode;
60
+ _nextNode = _node != nullptr ? _node->next : nullptr ;
61
+ return *this ;
62
+ }
54
63
bool operator != (const Iterator& i) const { return _node != i._node ; }
55
64
const T& operator * () const { return _node->value (); }
56
65
const T* operator -> () const { return &_node->value (); }
You can’t perform that action at this time.
0 commit comments