From 54ec441000b3e4cc192ab06d413aec76e5150982 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 3 Nov 2023 19:52:36 +0100 Subject: [PATCH] libluna: Add LinkedList::add_before() to mirror add_after() Need this for later. --- libluna/include/luna/LinkedList.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libluna/include/luna/LinkedList.h b/libluna/include/luna/LinkedList.h index 2e6d6a7a..a9e65276 100644 --- a/libluna/include/luna/LinkedList.h +++ b/libluna/include/luna/LinkedList.h @@ -108,6 +108,22 @@ template class LinkedList m_count++; } + void add_before(T* base, T* ptr) + { + Node* const new_node = extract_node(ptr); + Node* const base_node = extract_node(base); + + if (m_start_node == base_node) m_start_node = new_node; + + if (base_node->get_last()) base_node->get_last()->set_next(new_node); + + new_node->set_last(base_node->get_last()); + base_node->set_last(new_node); + new_node->set_next(base_node); + + m_count++; + } + T* remove(T* ptr) { Node* const node = extract_node(ptr);