From 0c32a964529105b611b600938c84df647f8fa0cf Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 11:54:41 +0200 Subject: [PATCH] some more singly linked list improvements --- container/SinglyLinkedList.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index a78a1467..85a92e6a 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -16,8 +16,13 @@ public: class Iterator { public: LinkedElement *value = nullptr; + //! Creates an uninitialized iterator which points to nullptr. Iterator() {} + /** + * Initialize iterator at specified linked element. + * @param element + */ Iterator(LinkedElement *element) : value(element) { } @@ -72,6 +77,11 @@ private: LinkedElement *next; }; +/** + * @brief SinglyLinkedList data structure which keeps a pointer to its + * first element to perform all operations. + * @tparam T + */ template class SinglyLinkedList { public: @@ -90,7 +100,11 @@ public: } ElementIterator end() const { - return ElementIterator::Iterator(); + LinkedElement *element = start; + while (element != nullptr) { + element = element->getNext(); + } + return ElementIterator::Iterator(element); } size_t getSize() const {