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\linkedlistnode.h" />
</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" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -28,18 +28,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</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>

View File

@ -8,8 +8,9 @@ namespace Datastructures {
public:
LinkedList();
~LinkedList();
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>>
{
public:
LinkedListNode(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
~LinkedListNode();
//Inherit Constructor from generic Undirectetd Node
using Generic::UndirectedNode<T, LinkedListNode<T>>::UndirectedNode;
std::shared_ptr<LinkedListNode<T>> create(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
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
template <typename T>
std::shared_ptr<LinkedListNode<T>> LinkedListNode<T>::create(T value, std::shared_ptr<LinkedListNode<T>> next) {