Cleaning up and adding comments

This commit is contained in:
Christopher Sanden
2025-11-20 15:24:00 +01:00
parent e77d7ff21e
commit a014e4ca73
7 changed files with 102 additions and 27 deletions

View File

@@ -3,7 +3,19 @@
#include "SharedLib.h"
TDoublyLinkedList::~TDoublyLinkedList()
{
const Node* cur = head;
while (cur) {
const Node* next = cur->GetNext();
delete cur;
cur = next;
}
head = tail = nullptr;
size = 0;
}
// Append a new line at the end of the list.
void TDoublyLinkedList::Append(const std::string& line)
{
auto* newNode = new Node(line);
@@ -17,6 +29,7 @@ void TDoublyLinkedList::Append(const std::string& line)
size++;
}
// Insert a new line at the beginning.
void TDoublyLinkedList::Prepend(const std::string& line)
{
auto* newNode = new Node(line);
@@ -43,6 +56,7 @@ TDoublyLinkedList::Node* TDoublyLinkedList::NavigateToNode(const int index) cons
return node;
}
// Removes the node at the given index and updates head/tail if needed.
void TDoublyLinkedList::Remove(const int index)
{
auto* node = NavigateToNode(index);