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

@@ -2,13 +2,16 @@
#define TDOUBLYLINKEDLIST_H
#include <string>
#include <utility>
#include "SharedLib.h"
// Doubly linked list used to store document lines.
// Supports insertion, removal, and indexed access.
// Chosen because it allows efficient updates in the middle of the document.
class TDoublyLinkedList {
private:
// Internal node storing a single line of text
// and links to previous and next nodes.
struct Node {
std::string line;
Node* next;
@@ -45,12 +48,21 @@ private:
public:
TDoublyLinkedList() : head(nullptr), tail(nullptr), size(0) {}
~TDoublyLinkedList() = default;
~TDoublyLinkedList();
void Append(const std::string &line);
void Prepend(const std::string& line);
// Returns pointer to node at given index.
// Linear traversal; used internally by Remove and InsertAtIndex.
[[nodiscard]] Node* NavigateToNode(int index) const;
// Removes a node at the given index.
// Updates links and frees the removed node.
void Remove(int index);
// Returns the text stored at the given index.
// Uses NavigateToNode internally.
[[nodiscard]] std::string GetAtIndex(int index) const;
void InsertAtIndex(int index, const std::string &line);
[[nodiscard]] int GetSize() const;