libluna: Add LinkedList::add_before() to mirror add_after()

Need this for later.
This commit is contained in:
apio 2023-11-03 19:52:36 +01:00
parent e1d5b7e7b4
commit 54ec441000
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -108,6 +108,22 @@ template <typename T> 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);