Updated Linked List to inherit generic constructors.

Not sure how the create method will integrate. Might integrate it into the linked list class so that it can just append it straight into the relevant node.
This commit is contained in:
Luke Else 2022-11-13 00:20:10 +00:00
parent e76f3b452e
commit 7a75d22514
4 changed files with 5 additions and 33 deletions

View File

@ -132,12 +132,6 @@
<ClInclude Include="src\LinkedList\linkedlist.h" /> <ClInclude Include="src\LinkedList\linkedlist.h" />
<ClInclude Include="src\LinkedList\linkedlistnode.h" /> <ClInclude Include="src\LinkedList\linkedlistnode.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClCompile Include="src\Generic\directednode.cpp" />
<ClCompile Include="src\Generic\undirectednode.cpp" />
<ClCompile Include="src\LinkedList\linkedlist.cpp" />
<ClCompile Include="src\LinkedList\linkedlistnode.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -28,18 +28,4 @@
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClCompile Include="src\Generic\directednode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Generic\undirectednode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\LinkedList\linkedlist.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\LinkedList\linkedlistnode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project> </Project>

View File

@ -8,8 +8,9 @@ namespace Datastructures {
public: public:
LinkedList(); LinkedList();
~LinkedList(); ~LinkedList();
private: private:
Nodes::LinkedListNode<T> mHead;
Nodes::LinkedListNode<T> mTail;
int mCount;
}; };
} }

View File

@ -7,21 +7,12 @@ namespace Datastructures {
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>> class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
{ {
public: public:
LinkedListNode(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr); //Inherit Constructor from generic Undirectetd Node
~LinkedListNode(); using Generic::UndirectedNode<T, LinkedListNode<T>>::UndirectedNode;
std::shared_ptr<LinkedListNode<T>> create(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr); std::shared_ptr<LinkedListNode<T>> create(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
private: private:
}; };
template <typename T>
LinkedListNode<T>::LinkedListNode(T value, std::shared_ptr<LinkedListNode<T>> next) {
this->value = value;
this->next = next;
}
//Creates a new node, returning a smart pointer to a stack allocated object //Creates a new node, returning a smart pointer to a stack allocated object
template <typename T> template <typename T>
std::shared_ptr<LinkedListNode<T>> LinkedListNode<T>::create(T value, std::shared_ptr<LinkedListNode<T>> next) { std::shared_ptr<LinkedListNode<T>> LinkedListNode<T>::create(T value, std::shared_ptr<LinkedListNode<T>> next) {