26 #ifndef LIST_DOUBLE_LINKED_LIST_HPP 27 #define LIST_DOUBLE_LINKED_LIST_HPP 42 Entry *prev =
nullptr;
43 Entry *next =
nullptr;
59 Entry *getNext()
const {
return next; }
66 void setNext(Entry *nextEntry) { next = nextEntry; }
73 Entry *getPrev()
const {
return prev; }
80 void setPrev(Entry *prevEntry) { prev = prevEntry; }
83 Entry *head =
nullptr;
84 Entry *tail =
nullptr;
97 if (index > abs(this->
getSize() / 2)) {
99 for (
int i = this->
getSize(); i > index + 1; --i) {
100 current = current->getPrev();
104 for (
int i = 0; i < index; i++) {
105 current = current->getNext();
109 return current->getValue(this->
isMutable());
141 Entry *entry =
new Entry();
142 entry->setValue(value, this->
isMutable());
150 entry->setNext(head);
151 head->setPrev(entry);
154 }
else if (index == this->
getSize()) {
156 tail->setNext(entry);
157 entry->setPrev(tail);
164 if (index >= abs(this->
getSize() / 2)) {
166 for (
int i = this->
getSize(); i > index + 1; --i) {
167 current = current->getPrev();
169 entry->setNext(current);
170 entry->setPrev(current->getPrev());
171 entry->getPrev()->setNext(entry);
172 current->setPrev(entry);
175 for (
int i = 0; i < index - 1; ++i) {
176 current = current->getNext();
178 entry->setNext(current->getNext());
179 entry->setPrev(current);
180 entry->getNext()->setPrev(entry);
181 current->setNext(entry);
196 Entry *current = head;
198 for (
int i = 0; i < this->
getSize(); ++i) {
199 next = current->getNext();
213 void remove(
int index)
override {
218 Entry *current = head;
221 if (index >= abs(this->
getSize() / 2)) {
225 while (i > index - 1) {
226 current = current->getPrev();
233 while (i < index - 1) {
234 current = current->getNext();
240 if (index == this->
getSize() - 1) {
245 head = current->getNext();
251 head = current->getNext();
253 toDelete = current->getNext();
254 current->setNext(current->getNext()->getNext());
255 if (current->getNext() !=
nullptr) {
256 current->getNext()->setPrev(current);
271 #endif// LIST_DOUBLE_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
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: DoubleLinkedList.hpp:134
#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
~DoubleLinkedList()
Destructor of a DoubleLinkedList Object.
Definition: DoubleLinkedList.hpp:125
T * getPointer(int index) override
The last entry of the list.
Definition: DoubleLinkedList.hpp:90
Definition: AbstractList.hpp:50
void decreaseSize()
Decrease the size of the list by one. Should only be called after an deletion!
Definition: AbstractList.hpp:115
Implementation of a double-linked list.
Definition: DoubleLinkedList.hpp:37
bool isMutable() const
Check if the list is mutable.
Definition: AbstractList.hpp:341
void clear() override
Remove all elements from the List.
Definition: DoubleLinkedList.hpp:191
Abstract class from which all lists can be derived.
Definition: AbstractList.hpp:37