diff options
Diffstat (limited to 'backend/ListIterator.hpp')
-rw-r--r-- | backend/ListIterator.hpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/backend/ListIterator.hpp b/backend/ListIterator.hpp index b6b7a36..30a556f 100644 --- a/backend/ListIterator.hpp +++ b/backend/ListIterator.hpp @@ -3,16 +3,16 @@ #include "ListIterator.h" template <typename T> -ListRange<T>::ListRange(const List<T> & list) : list(list) { } +ListRange<T>::ListRange(List<T> & list) : list(list) { } template <typename T> -ListIterator<T> ListRange<T>::begin() const { - return { this->list, 0 }; +ListIterator<T> ListRange<T>::begin() { + return { this->list.tail }; } template <typename T> -ListIterator<T> ListRange<T>::end() const { - return { this->list, this->list.size() }; +ListIterator<T> ListRange<T>::end() { + return { this->list.head }; } template <typename T> @@ -21,21 +21,27 @@ size_t ListRange<T>::size() const { } template <typename T> -ListIterator<T>::ListIterator(const List<T> & list, size_t index) : list(list), index(index) { } +ListIterator<T>::ListIterator(ListLink<T> * & here) { + this->here = here; + if (this->here != nullptr) + this->next = this->here->next; +} template <typename T> -T ListIterator<T>::operator * () const { - return this->list[this->index]; +T & ListIterator<T>::operator * () const { + return this->here->value; } template <typename T> ListIterator<T> & ListIterator<T>::operator ++ () { - this->index++; + this->here = this->next; + if (this->here != nullptr) + this->next = this->here->next; return *this; } template <typename T> bool ListIterator<T>::operator != (const ListIterator<T> & rhs) const { - return this->index < rhs.index; + return this->here != nullptr; } |