aboutsummaryrefslogtreecommitdiff
path: root/backend/List.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/List.hpp')
-rw-r--r--backend/List.hpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/backend/List.hpp b/backend/List.hpp
index a0d9289..17b6ce7 100644
--- a/backend/List.hpp
+++ b/backend/List.hpp
@@ -9,10 +9,11 @@ size_t List<T>::size() {
template <typename T>
void List<T>::push_back(T & el) {
- ListLink<T> * link = static_cast<ListLink<T> *>(malloc(sizeof(ListLink<T>)));
- link->prev = this->head;
- link->next = nullptr;
- link->value = el;
+ ListLink<T> * link = new ListLink<T> {
+ .prev = this->head,
+ .next = nullptr,
+ .value = el,
+ };
if (this->head != nullptr) this->head->next = link;
if (this->head == nullptr) this->tail = link;
this->head = link;
@@ -29,7 +30,7 @@ void List<T>::remove(const T & target) {
if (link->next != nullptr) link->next->prev = link->prev;
if (link->prev != nullptr) link->prev->next = link->next;
- free(link);
+ delete link;
this->length--;
}
@@ -40,7 +41,7 @@ void List<T>::pop_back() {
ListLink<T> * secondlast = this->head->prev;
if (secondlast != nullptr)
secondlast->next = nullptr;
- free(this->head);
+ delete this->head;
if (this->tail == this->head)
this->tail = nullptr;
this->head = secondlast;
@@ -53,7 +54,7 @@ void List<T>::clear() {
ListLink<T> * link = this->tail;
while (link != nullptr) {
ListLink<T> * next = link->next;
- free(link);
+ delete link;
link = next;
}
this->head = nullptr;