diff --git a/luna/include/luna/LinkedList.h b/luna/include/luna/LinkedList.h index 6f93d697..aeb5a695 100644 --- a/luna/include/luna/LinkedList.h +++ b/luna/include/luna/LinkedList.h @@ -45,12 +45,18 @@ template class DoublyLinkedListNode m_last_node->m_next_node = m_next_node; } - void add_to_list(SelfType* end_node) + void append_to_list(SelfType* end_node) { end_node->m_next_node = this; this->m_last_node = end_node; } + void prepend_to_list(SelfType* start_node) + { + start_node->m_last_node = this; + this->m_next_node = start_node; + } + friend class DoublyLinkedList; }; @@ -65,7 +71,7 @@ template class DoublyLinkedList { Node* const node = extract_node(ptr); if (!m_start_node) m_start_node = node; - if (m_end_node) node->add_to_list(m_end_node); + if (m_end_node) node->append_to_list(m_end_node); else { node->set_next(nullptr); @@ -76,6 +82,20 @@ template class DoublyLinkedList m_count++; } + void prepend(T* ptr) + { + Node* const node = extract_node(ptr); + if (m_start_node) node->prepend_to_list(m_start_node); + else + { + node->set_next(nullptr); + node->set_last(nullptr); + } + m_start_node = node; + + m_count++; + } + void add_after(T* base, T* ptr) { Node* const new_node = extract_node(ptr);