From 05d637acb5699444bd96490016ec374a267f8496 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sun, 13 Nov 2022 14:34:00 +0000 Subject: [PATCH] Updated Linked List - Added append function (Doesn't have access to Node member variables) --- DataStructures/src/LinkedList/linkedlist.h | 15 ++++++++ .../src/LinkedList/linkedlistnode.h | 3 +- DataStructuresCPP.vcxproj | 38 +++++++++---------- DataStructuresCPP.vcxproj.filters | 5 +++ src/main.cpp | 7 ++++ 5 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 src/main.cpp diff --git a/DataStructures/src/LinkedList/linkedlist.h b/DataStructures/src/LinkedList/linkedlist.h index 3fde77c..e48d05d 100644 --- a/DataStructures/src/LinkedList/linkedlist.h +++ b/DataStructures/src/LinkedList/linkedlist.h @@ -36,5 +36,20 @@ namespace Datastructures { mTail = mHead; } + template + LinkedList::~LinkedList() {} + template + void LinkedList::append(T value) { + mCount++; + if (mCount == 0) { + mHead = std::make_shared>(value); + mTail = mHead; + return; + } + + //Add new node and set to tail. + (*mTail).mNext = std::make_shared>(value); + mTail = (*mTail).mNext; + } } \ No newline at end of file diff --git a/DataStructures/src/LinkedList/linkedlistnode.h b/DataStructures/src/LinkedList/linkedlistnode.h index 9e5e734..e0f3d73 100644 --- a/DataStructures/src/LinkedList/linkedlistnode.h +++ b/DataStructures/src/LinkedList/linkedlistnode.h @@ -9,7 +9,8 @@ namespace Datastructures { public: //Inherit Constructor and destructor from generic Undirectetd Node using Generic::UndirectedNode>::UndirectedNode; - using Generic::UndirectedNode>::~UndirectedNode; + template + friend class LinkedList; private: }; } diff --git a/DataStructuresCPP.vcxproj b/DataStructuresCPP.vcxproj index 61fa226..a73efe1 100644 --- a/DataStructuresCPP.vcxproj +++ b/DataStructuresCPP.vcxproj @@ -17,7 +17,6 @@ Release x64 - 16.0 @@ -53,27 +52,24 @@ true Unicode - - + + + + + + + + + + + + + - - - - - - - - - - - - - - Level3 @@ -108,6 +104,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + $(SolutionDir)DataStructures\src;%(AdditionalIncludeDirectories) Console @@ -130,9 +127,10 @@ true - - + + + - + \ No newline at end of file diff --git a/DataStructuresCPP.vcxproj.filters b/DataStructuresCPP.vcxproj.filters index a8a6563..a12df58 100644 --- a/DataStructuresCPP.vcxproj.filters +++ b/DataStructuresCPP.vcxproj.filters @@ -14,4 +14,9 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Source Files + + \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..e40fb24 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() { + Datastructures::LinkedList list; + list.append(5); + list.append(200); +} \ No newline at end of file