some more singly linked list improvements

This commit is contained in:
Robin Müller 2020-06-24 11:54:41 +02:00
parent 8d633bf127
commit 0c32a96452

View File

@ -16,8 +16,13 @@ public:
class Iterator {
public:
LinkedElement<T> *value = nullptr;
//! Creates an uninitialized iterator which points to nullptr.
Iterator() {}
/**
* Initialize iterator at specified linked element.
* @param element
*/
Iterator(LinkedElement<T> *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<typename T>
class SinglyLinkedList {
public:
@ -90,7 +100,11 @@ public:
}
ElementIterator end() const {
return ElementIterator::Iterator();
LinkedElement<T> *element = start;
while (element != nullptr) {
element = element->getNext();
}
return ElementIterator::Iterator(element);
}
size_t getSize() const {