These are the fixes needed to make the whole piece compile and run.
p.44 "Implement a Simple Iterator":
#include <iostream>
+#include <algorithm> // std::find
// !! List implementation here
p.45 "Implement a Simple Iterator (List declaration)":
replace head -> _head
- It begin() { return It{head}; } // begin of the list
+ It begin() { return It{_head}; } // begin of the list
It end() { return It{nullptr}; } // end of the list
};
p.46 "Implement a Simple Iterator (List definition)":
replace head -> head, tail -> _tail
void List::push_back(const value_t& value) {
auto new_node = new Node{value, nullptr};
- if (head == nullptr) { // empty list
- head = new_node; // head is updated
- tail = head;
+ if (_head == nullptr) { // empty list
+ _head = new_node; // head is updated
+ _tail = _head;
return;
}
- assert(tail != nullptr);
- tail->_next = new_node; // add new node at the end
- tail = new_node; // tail is updated
+ assert(_tail != nullptr);
+ _tail->_next = new_node; // add new node at the end
+ _tail = new_node; // tail is updated
}
p.47 "Implement a Simple Iterator (Iterator declaration)":
replace second parameter itA -> itB
These are the fixes needed to make the whole piece compile and run.
p.44 "Implement a Simple Iterator":
p.45 "Implement a Simple Iterator (List declaration)": replace head -> _head
p.46 "Implement a Simple Iterator (List definition)": replace head -> head, tail -> _tail
p.47 "Implement a Simple Iterator (Iterator declaration)": replace second parameter itA -> itB
p.48 "Implement a Simple Iterator (Iterator definition)":
-value_t& It::operator() { return _ptr->_data; } +value_t& List::It::operator() { return _ptr->_value; }
-bool operator!=(const It& itA, const It& itB) { +bool operator!=(const List::It& itA, const List::It& itB) { return itA._ptr != itB._ptr; }
-It& It::operator++() { +List::It& List::It::operator++() { _ptr = _ptr->_next; return this; } -It It::operator++(int) { +List::It List::It::operator++(int) { auto tmp = this; ++(*this); return tmp; }