Files
Datastructs/Exam/part1/TDoublyLinkedList.h
Christopher Sanden a8006be05f Adding exam part 1/4
2025-11-03 21:30:23 +01:00

67 lines
1.3 KiB
C++

#ifndef PART1_TDOUBLYLINKEDLIST_H
#define PART1_TDOUBLYLINKEDLIST_H
#include <string>
#include <utility>
class TDoublyLinkedList {
private:
struct Node {
std::string line;
Node* next;
Node* prev;
explicit Node(std::string text) : line(std::move(text)), next(nullptr), prev(nullptr) {}
void SetNext(Node* node)
{
this->next = node;
}
void SetPrev(Node* node)
{
this->prev = node;
}
[[nodiscard]] Node* GetPrev() const
{
return this->prev;
}
[[nodiscard]] Node* GetNext() const
{
return this->next;
}
[[nodiscard]] std::string GetLine() const
{
return line;
}
};
Node* head;
Node* tail;
int size;
public:
TDoublyLinkedList() : head(nullptr), tail(nullptr), size(0) {}
~TDoublyLinkedList() = default;
void Append(const std::string &line);
void Prepend(const std::string& line);
[[nodiscard]] Node* NavigateToNode(int index) const;
void Remove(int index);
[[nodiscard]] std::string GetAtIndex(int index) const;
void InsertAtIndex(int index, const std::string &line);
[[nodiscard]] int GetSize() const;
};
#endif //PART1_TDOUBLYLINKEDLIST_H