summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-05-05 10:35:25 +0200
committerLinus Groh <mail@linusgroh.de>2022-06-10 19:06:46 +0100
commitb3e0aed91f1c15c1223b23864efac6d90f31324a (patch)
treea633d16196e84665d5ded2cdb84b61adf7f2a6b0 /AK
parenta39c38840eec545ab76979a5a6601b9dc9ad027c (diff)
downloadserenity-b3e0aed91f1c15c1223b23864efac6d90f31324a.zip
AK: Add SinglyLinkedList::prepend()
Diffstat (limited to 'AK')
-rw-r--r--AK/SinglyLinkedList.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h
index 284aa3c3d4..79babf10e5 100644
--- a/AK/SinglyLinkedList.h
+++ b/AK/SinglyLinkedList.h
@@ -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();