From f8d8d7499ba4433678db2a68fb1cae74448ca31e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 31 Oct 2024 14:14:09 +0100 Subject: make ListIterator continue working on a changing list --- backend/ListIterator.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'backend/ListIterator.hpp') 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 -ListRange::ListRange(const List & list) : list(list) { } +ListRange::ListRange(List & list) : list(list) { } template -ListIterator ListRange::begin() const { - return { this->list, 0 }; +ListIterator ListRange::begin() { + return { this->list.tail }; } template -ListIterator ListRange::end() const { - return { this->list, this->list.size() }; +ListIterator ListRange::end() { + return { this->list.head }; } template @@ -21,21 +21,27 @@ size_t ListRange::size() const { } template -ListIterator::ListIterator(const List & list, size_t index) : list(list), index(index) { } +ListIterator::ListIterator(ListLink * & here) { + this->here = here; + if (this->here != nullptr) + this->next = this->here->next; +} template -T ListIterator::operator * () const { - return this->list[this->index]; +T & ListIterator::operator * () const { + return this->here->value; } template ListIterator & ListIterator::operator ++ () { - this->index++; + this->here = this->next; + if (this->here != nullptr) + this->next = this->here->next; return *this; } template bool ListIterator::operator != (const ListIterator & rhs) const { - return this->index < rhs.index; + return this->here != nullptr; } -- cgit v1.2.3