Explorar o código

Added LinkedList + Array Iosif

Vsevolod Levitan hai 11 meses
pai
achega
5a9381309b

+ 31 - 0
LinkedList_Array/ConsoleApplication1.sln

@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.11.34909.67
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{7828E00D-7383-48A4-882E-20C449AA9946}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Debug|x64.ActiveCfg = Debug|x64
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Debug|x64.Build.0 = Debug|x64
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Debug|x86.ActiveCfg = Debug|Win32
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Debug|x86.Build.0 = Debug|Win32
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Release|x64.ActiveCfg = Release|x64
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Release|x64.Build.0 = Release|x64
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Release|x86.ActiveCfg = Release|Win32
+		{7828E00D-7383-48A4-882E-20C449AA9946}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {F2FE1E6B-14D0-4BB8-99DB-0C594D85B04C}
+	EndGlobalSection
+EndGlobal

+ 159 - 0
LinkedList_Array/ConsoleApplication1/Array.cpp

@@ -0,0 +1,159 @@
+#include <iostream>
+#include "Array.h"
+
+using namespace std;
+
+
+class ArrayException {};
+
+Array::Array(int startCapacity)
+{
+	{
+		if (startCapacity <= 0)
+		{
+			capacity = DEFAULT_CAPACITY;
+		}
+
+		else
+		{
+			capacity = startCapacity;
+		}
+
+		ptr = new int[capacity];
+	}
+}
+
+Array::Array(const Array& arr)
+{
+	ptr = new int[arr.capacity];
+	size = arr.size;
+	capacity = arr.capacity;
+	for (int i = 0; i < size; i++)
+	{
+		ptr[i] = arr.ptr[i];
+	}
+}
+
+Array::~Array()
+{
+	delete[] ptr;
+}
+
+Array& Array::operator = (const Array& arr)
+{
+
+	if (this == &arr)
+	{
+		return *this;
+	}
+
+	if (capacity != arr.capacity)
+	{
+
+		delete[] ptr;
+		ptr = new int[arr.capacity];
+		capacity = arr.capacity;
+
+	}
+
+	size = arr.size;
+
+	for (int i = 0; i < size; i++)
+	{
+		ptr[i] = arr.ptr[i];
+	}
+
+	return *this;
+
+}
+
+int& Array::operator [] (int index)
+{
+	if (index >= size || index < 0)
+	{
+		throw ArrayException();
+		cout << "The index is outside the bounds of array" << endl;
+	}
+
+	else
+	{
+		return ptr[index];
+	}
+}
+
+void Array::increaseCapacity(int newCapacity)
+{
+
+	if (newCapacity < capacity * 2) {
+		capacity = capacity * 2;
+	}
+
+	else {
+		capacity = newCapacity;
+	}
+
+	int* newPtr = new int[capacity];
+
+	for (int i = 0; i < size; i++)
+	{
+		newPtr[i] = ptr[i];
+	}
+
+	delete[] ptr;
+	ptr = newPtr;
+}
+
+void Array::insert(int elem, int index)
+{
+
+	if (index < 0 || index > size)
+	{
+		throw ArrayException();
+	}
+
+	if (size == capacity)
+	{
+		increaseCapacity(size + 1);
+	}
+
+	for (int j = size - 1; j >= index; j--)
+	{
+		ptr[j + 1] = ptr[j];
+	}
+
+	size++;
+	ptr[index] = elem;
+}
+
+void Array::remove(int index)
+{
+
+	if (index < 0 || index >= size)
+	{
+		throw ArrayException();
+	}
+
+	for (int j = index; j < size - 1; j++)
+	{
+		ptr[j] = ptr[j + 1];
+	}
+
+	ptr[size - 1] = 0;
+	size--;
+
+}
+
+int Array::getSize() const
+{
+	return size;
+}
+
+ostream& operator <<(ostream& out, const Array& arr)
+{
+	out << "Total size: " << arr.size << endl;
+	for (int i = 0; i < arr.size; i++)
+	{
+		out << arr.ptr[i] << endl;
+	}
+	return out;
+}

+ 55 - 0
LinkedList_Array/ConsoleApplication1/Array.h

@@ -0,0 +1,55 @@
+#pragma once
+#include <iostream>
+using namespace std;
+const int DEFAULT_CAPACITY = 10;
+
+/// <summary>
+/// An array holding some integer values
+/// </summary>
+class Array
+{
+private:
+    int* ptr;
+
+    int size, capacity;
+
+    /// <summary>
+    /// Increase the capacity of the array
+    /// </summary>
+    /// <param name="newCapacity">New capacity</param>
+    void increaseCapacity(int newCapacity);
+
+public:
+
+    explicit Array(int startCapacity = DEFAULT_CAPACITY);
+
+    Array(const Array&);
+
+    ~Array();
+
+    Array& operator = (const Array& arr);
+
+    int& operator [] (int index);
+
+    /// <summary>
+    /// Insert element into position
+    /// </summary>
+    /// <param name="elem">The value to be inserted</param>
+    /// <param name="index">The position to insert the value into</param>
+    void insert(int elem, int index);
+
+    /// <summary>
+    /// Remove element from array
+    /// </summary>
+    /// <param name="index">The index of the element to be removed</param>
+    void remove(int index);
+
+    /// <summary>
+    /// Get current size of the array
+    /// </summary>
+    /// <returns>The size of the array</returns>
+    int getSize() const;
+
+
+    friend ostream& operator <<(ostream& out, const Array& arr);
+};

+ 92 - 0
LinkedList_Array/ConsoleApplication1/ConsoleApplication1.cpp

@@ -0,0 +1,92 @@
+#include <iostream>
+#include <chrono>
+#include "LinkedList.h"
+#include "LinkedListNode.h"
+#include "Array.h"
+
+using namespace std;
+
+static int iosif_ll(int step, int count)
+{
+	LinkedList<int> list;
+	for (int i = count; i > 0; i--)
+	{
+		list.insertFirst(i);
+	}
+	list.makeCircular();
+	LinkedListNode<int>* it = list.getStart();
+	for (int i = 0; i < step - 2; i++)
+	{
+		it = it->getNext();
+	}
+	list.deleteAfter(it);
+	while (list.getStart() != list.getStart()->getNext())
+	{
+		for (int i = 0; i < step - 1; i++)
+		{
+			it = it->getNext();
+		}
+		list.deleteAfter(it);
+	}
+	cout << "N = " << count << " " << "K = " << step << " survivor: " << list << " ";
+	return 0;
+}
+
+int iosif_arr(int N, int K)
+{
+	Array arr(N);
+
+	for (int i = 1; i <= N; i++)
+	{
+
+		arr.insert(i, i - 1);
+
+	}
+
+	int DELETE = 0;
+
+
+	while (arr.getSize() > 1)
+	{
+		DELETE += (K - 1) % arr.getSize();
+		if (DELETE >= arr.getSize())
+		{
+			DELETE = DELETE % arr.getSize();
+			arr.remove(DELETE);
+		}
+		else
+		{
+			arr.remove(DELETE);
+		}
+
+	}
+	cout << "N = " << N << " K = " << K << " survivor: " << arr[0];
+	return 0;
+}
+
+int main()
+{
+	cout << "Linked list:" << endl;
+
+	int K = 2, arr[7] = { 1000,5000,10000,50000,100000,500000,1000000 };
+	for (int i = 0; i < 7; i++)
+	{
+		auto start = std::chrono::high_resolution_clock::now();
+		iosif_ll(K, arr[i]);
+		auto end = std::chrono::high_resolution_clock::now();
+		std::chrono::duration<double> diff = end - start;
+		std::cout << "Time " << diff.count() << endl;
+	}
+
+	cout << endl << endl << "Array:" << endl;
+
+	for (int i = 0; i < 7; i++)
+	{
+		auto start = std::chrono::high_resolution_clock::now();
+		iosif_arr(K, arr[i]);
+		auto end = std::chrono::high_resolution_clock::now();
+		std::chrono::duration<double> diff = end - start;
+		std::cout << " Time " << diff.count() << endl;
+	}
+	return 0;
+}

+ 141 - 0
LinkedList_Array/ConsoleApplication1/ConsoleApplication1.vcxproj

@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <VCProjectVersion>17.0</VCProjectVersion>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectGuid>{7828e00d-7383-48a4-882e-20c449aa9946}</ProjectGuid>
+    <RootNamespace>ConsoleApplication1</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="Array.cpp" />
+    <ClCompile Include="ConsoleApplication1.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Array.h" />
+    <ClInclude Include="LinkedList.h" />
+    <ClInclude Include="LinkedListNode.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 36 - 0
LinkedList_Array/ConsoleApplication1/ConsoleApplication1.vcxproj.filters

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="ConsoleApplication1.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Array.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="LinkedList.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="LinkedListNode.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Array.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>

+ 168 - 0
LinkedList_Array/ConsoleApplication1/LinkedList.h

@@ -0,0 +1,168 @@
+#pragma once
+#include <iostream>
+
+// Forward declaration of LinkedListNode
+template <typename T> class LinkedListNode;
+
+class LinkedListException {};
+/// <summary>
+/// Class representing a linked list
+/// </summary>
+/// <typeparam name="T">Value type</typeparam>
+template <typename T> class LinkedList {
+    bool isCircular;
+    LinkedListNode<T>* start;
+
+    /// <summary>
+    /// Copies the linked list to another instance
+    /// </summary>
+    /// <param name="list">Pointer to original linked list</param>
+    LinkedList(const LinkedList& list);
+
+    /// <summary>
+    /// Assignment operator override
+    /// </summary>
+    /// <param name="list">The original linked list to be copied</param>
+    /// <returns>The copied linked list</returns>
+    LinkedList& operator =(const LinkedList& list);
+
+public:
+    LinkedList();
+    ~LinkedList();
+
+    /// <summary>
+    /// Get the starting node of the linked list
+    /// </summary>
+    /// <returns>First node of the list</returns>
+    LinkedListNode<T>* getStart();
+
+    /// <summary>
+    /// Delete the first item
+    /// </summary>
+    void deleteFirst();
+
+    /// <summary>
+    /// Delete the item following the node
+    /// </summary>
+    /// <param name="ptr">The node before the item to delete</param>
+    void deleteAfter(LinkedListNode<T>* ptr);
+
+    /// <summary>
+    /// Insert some value into the new node in the beginning
+    /// </summary>
+    /// <param name="data">The value to be inserted</param>
+    void insertFirst(const T& value);
+
+    /// <summary>
+    /// Insert some value after the node
+    /// </summary>
+    /// <param name="ptr">The node after which the value shall be inserted</param>
+    /// <param name="data">The value to be inserted</param>
+    void insertAfter(LinkedListNode<T>* ptr, const T& value);
+
+    /// <summary>
+    /// Make the linked list circular (looped)
+    /// </summary>
+    void makeCircular();
+
+    /// <summary>
+    /// Output operator override
+    /// </summary>
+    /// <typeparam name="T">Some type</typeparam>
+    /// <param name="out">Outbound stream</param>
+    /// <param name="list">Linked list to be printed out</param>
+    /// <returns>Outbound stream containing serialized values of the linked list</returns>
+    template <typename U> friend std::ostream& operator <<(std::ostream& out, LinkedList<U>& list);
+};
+
+// Implementation of LinkedList
+
+template <typename T> LinkedList<T>::LinkedList()
+    : start(nullptr), isCircular(false) {}
+
+template <typename T> LinkedList<T>::~LinkedList() {
+    if (isCircular) {
+        LinkedListNode<T>* current = start;
+        while (current->_next != start) {
+            current = current->_next;
+        }
+        current->_next = nullptr;
+    }
+    while (start) {
+        deleteFirst();
+    }
+}
+
+template <typename T> LinkedListNode<T>* LinkedList<T>::getStart() {
+    return start;
+}
+
+template <typename T> void LinkedList<T>::deleteFirst() {
+    if (start) {
+        LinkedListNode<T>* temp = start->_next;
+        delete start;
+        start = temp;
+    }
+    else {
+        throw LinkedListException();
+    }
+}
+
+template <typename T> void LinkedList<T>::deleteAfter(LinkedListNode<T>* ptr) {
+    if (ptr && ptr->_next) {
+        if (ptr->_next == start) {
+            LinkedListNode<T>* temp = ptr->_next;
+            ptr->_next = ptr->_next->_next;
+            delete temp;
+            start = ptr->_next;
+        }
+        else {
+            LinkedListNode<T>* temp = ptr->_next;
+            ptr->_next = ptr->_next->_next;
+            delete temp;
+        }
+    }
+    else {
+        throw LinkedListException();
+    }
+}
+
+template <typename T> void LinkedList<T>::insertFirst(const T& value) {
+    LinkedListNode<T>* second = start;
+    start = new LinkedListNode<T>(value, second);
+}
+
+template <typename T> void LinkedList<T>::insertAfter(LinkedListNode<T>* ptr, const T& value) {
+    if (ptr) {
+        LinkedListNode<T>* temp = ptr->_next;
+        ptr->_next = new LinkedListNode<T>(value, temp);
+    }
+}
+
+template <typename T> std::ostream& operator<<(std::ostream& out, LinkedList<T>& list) {
+    LinkedListNode<T>* ptr = list.getStart();
+    if (!ptr) {
+        out << "EMPTY ";
+    }
+    else {
+        do {
+            out << ptr->getValue() << ' ';
+            ptr = ptr->getNext();
+        } while (ptr && ptr != list.getStart());
+    }
+    return out;
+}
+
+template <typename T> void LinkedList<T>::makeCircular() {
+    if (start == nullptr) {
+        return;
+    }
+
+    LinkedListNode<T>* current = start;
+    while (current->_next != nullptr) {
+        current = current->_next;
+    }
+
+    current->_next = start;
+    isCircular = true;
+}

+ 70 - 0
LinkedList_Array/ConsoleApplication1/LinkedListNode.h

@@ -0,0 +1,70 @@
+#pragma once
+#include <iostream>
+
+// Forward declaration of LinkedList
+template <typename T> class LinkedList;
+
+/// <summary>
+/// Template class to allow the LinkedListNode to store any data type
+/// </summary>
+/// <typeparam name="T">Value type</typeparam>
+template <typename T>
+class LinkedListNode {
+private:
+    T _value; // Value of the node
+    LinkedListNode* _next; // Pointer to the next node in the linked list
+
+public:
+    /// <summary>
+    /// Linked list item constructor
+    /// </summary>
+    /// <param name="value">The value of the node</param>
+    /// <param name="next">The next node in the linked list</param>
+    LinkedListNode(const T& value, LinkedListNode* next);
+
+    /// <summary>
+    /// Retrieve the value of the node
+    /// </summary>
+    /// <returns>The respective value for the node</returns>
+    const T& getValue() const;
+
+    /// <summary>
+    /// Retrieve next node in the linked list
+    /// </summary>
+    /// <returns>Next linked node</returns>
+    LinkedListNode* getNext();
+
+    /// <summary>
+    /// Assigns the item new value
+    /// </summary>
+    /// <param name="other">The value to be replaced with</param>
+    /// <returns>New linked list item</returns>
+    LinkedListNode<T>& operator=(const LinkedListNode<T>& other);
+
+    template <typename U> friend class LinkedList;
+};
+
+// Implementation of LinkedListNode
+
+template <typename T>
+LinkedListNode<T>::LinkedListNode(const T& value, LinkedListNode* next)
+    : _value(value), _next(next) {}
+
+template<typename T>
+const T& LinkedListNode<T>::getValue() const {
+    return _value;
+}
+
+template <typename T>
+LinkedListNode<T>* LinkedListNode<T>::getNext() {
+    return _next;
+}
+
+template <typename T>
+LinkedListNode<T>& LinkedListNode<T>::operator=(const LinkedListNode<T>& other) {
+    if (this != &other) {
+        _value = other._value;
+        _next = other._next;
+    }
+    return *this;
+}