AK: Add SinglyLinkedList::prepend()

This commit is contained in:
Tim Schumacher 2022-05-05 10:35:25 +02:00 committed by Linus Groh
parent a39c38840e
commit b3e0aed91f

View file

@ -160,6 +160,19 @@ public:
m_tail = node;
}
template<typename U = T>
void prepend(U&& value)
{
auto* node = new Node(forward<U>(value));
if (!m_head) {
m_head = node;
m_tail = node;
return;
}
node->next = m_head;
m_head = node;
}
bool contains_slow(const T& value) const
{
return find(value) != end();