mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 20:55:35 +03:00
Make SinglyLinkedList destruction actually work.
This commit is contained in:
parent
6ea8ce500c
commit
b7efd92937
Notes:
sideshowbarker
2024-07-19 18:49:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b7efd92937e
@ -8,16 +8,28 @@ template<typename T>
|
||||
class SinglyLinkedList {
|
||||
private:
|
||||
struct Node {
|
||||
explicit Node(T&& v) : value(v) { }
|
||||
T value;
|
||||
Node* next { nullptr };
|
||||
};
|
||||
|
||||
public:
|
||||
SinglyLinkedList() { }
|
||||
~SinglyLinkedList() { }
|
||||
~SinglyLinkedList() { clear(); }
|
||||
|
||||
bool isEmpty() const { return !head(); }
|
||||
|
||||
void clear()
|
||||
{
|
||||
for (auto* node = m_head; node; ) {
|
||||
auto* next = node->next;
|
||||
delete node;
|
||||
node = next;
|
||||
}
|
||||
m_head = nullptr;
|
||||
m_tail = nullptr;
|
||||
}
|
||||
|
||||
T& first() { ASSERT(head()); return head()->value; }
|
||||
const T& first() const { ASSERT(head()); return head()->value; }
|
||||
T& last() { ASSERT(head()); return tail()->value; }
|
||||
@ -25,8 +37,7 @@ public:
|
||||
|
||||
void append(T&& value)
|
||||
{
|
||||
auto* node = new Node;
|
||||
node->value = std::move(value);
|
||||
auto* node = new Node(std::move(value));
|
||||
if (!m_head) {
|
||||
m_head = node;
|
||||
m_tail = node;
|
||||
|
Loading…
Reference in New Issue
Block a user