From 6ea7d4127e30917df9e60ee8092511d747ba884b Mon Sep 17 00:00:00 2001 From: Oyale Date: Sat, 14 Jan 2023 23:17:09 +0100 Subject: [PATCH 1/2] Started Linked List Implementation --- LittleTemplateLibrary.vcxproj | 1 + LittleTemplateLibrary.vcxproj.filters | 3 ++ src/Array.cpp | 2 +- src/List.cpp | 43 +++++++++++++++ src/List.h | 75 +++++++++++---------------- src/Util.h | 2 + 6 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 src/List.cpp diff --git a/LittleTemplateLibrary.vcxproj b/LittleTemplateLibrary.vcxproj index bfd3ad7..7d2428a 100644 --- a/LittleTemplateLibrary.vcxproj +++ b/LittleTemplateLibrary.vcxproj @@ -140,6 +140,7 @@ + diff --git a/LittleTemplateLibrary.vcxproj.filters b/LittleTemplateLibrary.vcxproj.filters index e2f10ff..0b792af 100644 --- a/LittleTemplateLibrary.vcxproj.filters +++ b/LittleTemplateLibrary.vcxproj.filters @@ -27,6 +27,9 @@ Source Files + + Source Files + diff --git a/src/Array.cpp b/src/Array.cpp index 7b961bb..7fde5e5 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -29,7 +29,7 @@ namespace Ltl T Array::operator[](const int index) { //Bounds checking - if ((index => 0) && (index !> len-1)) + if ((index >= 0) && !(index > len-1)) { return body[index]; } diff --git a/src/List.cpp b/src/List.cpp new file mode 100644 index 0000000..f6974c2 --- /dev/null +++ b/src/List.cpp @@ -0,0 +1,43 @@ +#include "List.h" + +namespace Ltl +{ + template + LinkedList::LinkedList() + { + //The head is the first element and it points to nothing in this case + head = new Node(T(), nullptr, nullptr); + } + + template + inline int Ltl::LinkedList::size() + { + return len; + } + + template + bool LinkedList::empty() + { + if (len > 0) + { + return false; + } + return true; + } + + template + void LinkedList::push(const T value) + { + Node next; + + for (int i = 0; i < len; i++) + { + + } + + if (head.next == nullptr) + { + next = new Node(value, &head, nullptr); + } + } +} \ No newline at end of file diff --git a/src/List.h b/src/List.h index 825fcef..c27b6de 100644 --- a/src/List.h +++ b/src/List.h @@ -3,56 +3,41 @@ namespace Ltl { template - class List + class LinkedList { public: - //Constructor - List(){} - List(const int& size); - void operator=(const List& s); - - //Destructor - ~List(); - - #pragma region Access Functions - /// The first element in the list - T front(); - /// The last element in the list - T back(); - #pragma endregion Functions for accessing the elements of the container - - #pragma region Member Functions - /// The size of the container + /// Default Constructor + LinkedList(); + int size(); - /// True if the container is empty, false otherwise bool empty(); - #pragma endregion - #pragma region Modifier Functions - void insert(const T& value, const int& position); - void clear(); - void resize(const int& size); - void swap(); - void emplace_back(const T& value); - void emplace_front(const T& value); - void push_back(const T& value); - void push_front(const T& value); - void pop_back(); - void pop_front(); - #pragma endregion Modifies the container elements - - #pragma region Operations - List merge(List s); - void sort(); - #pragma endregion Operations on the container class + void push(const T value); - #pragma region Operator Overload - bool operator==(List& s); - bool operator<=(List& s); - bool operator>=(List& s); - bool operator<(List& s); - bool operator>(List& s); - bool operator!=(List& s); - #pragma endregion Overloading Functions + private: + template + struct Node + { + public: + T value; //Value of the current element + Node* prev; //A pointer to the previous element + Node* next; //A pointer to the next element + + /// Creates a new node item + /// Value to store in the node + /// Pointer to the previous element + /// Pointer to the next element or back to the head + Node(const T _value, Node* _prev, Node* _next) + { + value = _value; + prev = _prev; + next = _next; + } + }; + + Node head; //Represents the begining of the list + int len = 0; }; + + LinkedList list; } \ No newline at end of file diff --git a/src/Util.h b/src/Util.h index 8067331..b196913 100644 --- a/src/Util.h +++ b/src/Util.h @@ -1,4 +1,6 @@ #pragma once +#include "Array.h" +#include "Queue.h" namespace Ltl { From 91359ba8411a1b8b4227ae5457f2c71cebc0a75b Mon Sep 17 00:00:00 2001 From: Oyale Date: Mon, 16 Jan 2023 14:27:08 +0100 Subject: [PATCH 2/2] Started Tree Implementation --- LittleTemplateLibrary.vcxproj | 1 + LittleTemplateLibrary.vcxproj.filters | 3 +++ src/List.h | 7 ++----- src/Tree.h | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/Tree.h diff --git a/LittleTemplateLibrary.vcxproj b/LittleTemplateLibrary.vcxproj index 7d2428a..75ac64d 100644 --- a/LittleTemplateLibrary.vcxproj +++ b/LittleTemplateLibrary.vcxproj @@ -151,6 +151,7 @@ + diff --git a/LittleTemplateLibrary.vcxproj.filters b/LittleTemplateLibrary.vcxproj.filters index 0b792af..b876bb1 100644 --- a/LittleTemplateLibrary.vcxproj.filters +++ b/LittleTemplateLibrary.vcxproj.filters @@ -50,5 +50,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/List.h b/src/List.h index c27b6de..de6a4b6 100644 --- a/src/List.h +++ b/src/List.h @@ -15,8 +15,7 @@ namespace Ltl void push(const T value); private: - template - struct Node + class Node { public: T value; //Value of the current element @@ -35,9 +34,7 @@ namespace Ltl } }; - Node head; //Represents the begining of the list + Node head; //Represents the begining of the list int len = 0; }; - - LinkedList list; } \ No newline at end of file diff --git a/src/Tree.h b/src/Tree.h new file mode 100644 index 0000000..3326d2b --- /dev/null +++ b/src/Tree.h @@ -0,0 +1,25 @@ +#pragma once + +namespace Ltl +{ + template + class Tree + { + public: + Tree(){} + + private: + class Node + { + public: + Node() + { + L = nullptr; + R = nullptr; + } + + T Value; + Node* L, R; + }; + }; +} \ No newline at end of file