26 #ifndef LIST_SINGLE_LINKED_LIST_HPP 27 #define LIST_SINGLE_LINKED_LIST_HPP 42 Entry *next =
nullptr;
48 ~Entry() { next =
nullptr; }
55 Entry *getNext()
const {
return next; };
62 void setNext(Entry *nextEntry) { next = nextEntry; }
65 Entry *head =
nullptr;
66 Entry *tail =
nullptr;
77 Entry *current = head;
80 current = current->getNext();
83 return current->getValue(this->
isMutable());
118 entry->setValue(value, this->
isMutable());
126 entry->setNext(head);
129 }
else if (index == this->
getSize()) {
131 tail->setNext(entry);
135 Entry *current = head;
136 for (
int i = 0; i < index - 1; ++i) {
137 current = current->getNext();
139 entry->setNext(current->getNext());
140 current->setNext(entry);
154 Entry *current = head;
156 for (
int i = 0; i < this->
getSize(); ++i) {
157 next = current->getNext();
171 void remove(
int index)
override {
176 Entry *current = head;
181 while (i < index - 1) {
182 current = current->getNext();
187 if (index == this->
getSize() - 1) {
194 head = current->getNext();
196 toDelete = current->getNext();
197 current->setNext(current->getNext()->getNext());
211 #endif// LIST_SINGLE_LINKED_LIST_HPP void resetSize()
Reset the size to zero.
Definition: AbstractList.hpp:120
int getSize() const
Get the number how many elements are saved in the list.
Definition: AbstractList.hpp:334
~SingleLinkedList()
Destructor of a SingleLinkedList Object.
Definition: SingleLinkedList.hpp:99
void clear() override
Remove all elements from the List.
Definition: SingleLinkedList.hpp:149
#define extendedIsIndexOutOfBounds(index)
Is the list mutable or immutable.
Definition: AbstractList.hpp:44
bool isIndexOutOfBounds(const int index) const
Method to verify if the given index is out of the range of the list size.
Definition: AbstractList.hpp:130
void increaseSize()
Increase the size of the list by one. Should only be called after an insertion!
Definition: AbstractList.hpp:109
T * getPointer(int index) override
The last entry of the list.
Definition: SingleLinkedList.hpp:72
void addAtIndex(int index, T &value) override
Add the value to the list at the given index. The original entry at this index, and followings...
Definition: SingleLinkedList.hpp:108
Definition: AbstractList.hpp:50
Implementation of a single-linked list.
Definition: SingleLinkedList.hpp:37
void decreaseSize()
Decrease the size of the list by one. Should only be called after an deletion!
Definition: AbstractList.hpp:115
bool isMutable() const
Check if the list is mutable.
Definition: AbstractList.hpp:341
Abstract class from which all lists can be derived.
Definition: AbstractList.hpp:37