aboutsummaryrefslogtreecommitdiff
path: root/backend/List.hpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:34:29 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:34:29 +0100
commit71380426426dffe787d1704a8fd639c4b1bbfad3 (patch)
treef550cc1dfa100e208712e20b4442687cc2a7f157 /backend/List.hpp
parenta3c1ba7b49e4c5901d7c9dd917049744ad20fc96 (diff)
cmd_get complete
Diffstat (limited to 'backend/List.hpp')
-rw-r--r--backend/List.hpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/backend/List.hpp b/backend/List.hpp
index df075f9..a0d9289 100644
--- a/backend/List.hpp
+++ b/backend/List.hpp
@@ -8,7 +8,7 @@ size_t List<T>::size() {
}
template <typename T>
-void List<T>::push_back(T el) {
+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;
@@ -20,6 +20,20 @@ void List<T>::push_back(T el) {
}
template <typename T>
+void List<T>::remove(const T & target) {
+ ListLink<T> * link = nullptr;
+ for (link = this->tail; link != nullptr; link = link->next) {
+ if (link->value == target) break;
+ }
+ if (link == nullptr) return; // target not in list
+
+ if (link->next != nullptr) link->next->prev = link->prev;
+ if (link->prev != nullptr) link->prev->next = link->next;
+ free(link);
+ this->length--;
+}
+
+template <typename T>
void List<T>::pop_back() {
if (this->head == nullptr) return; // empty list