Added Create method to Linked List Node

This commit is contained in:
Luke Else 2022-11-07 14:00:04 +00:00
parent 9ec4e515f2
commit deb58f03bb
4 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
namespace Datastructures { namespace Datastructures {
template <typename T>
class LinkedList class LinkedList
{ {
public: public:
@ -9,12 +10,4 @@ namespace Datastructures {
private: private:
}; };
LinkedList::LinkedList()
{
}
LinkedList::~LinkedList()
{
}
} }

View File

@ -2,6 +2,16 @@
namespace Datastructures { namespace Datastructures {
namespace Nodes { namespace Nodes {
template <typename T>
LinkedListNode<T>::LinkedListNode(T value, LinkedListNode<T>* next) {
this->value = value;
this->next = next;
}
//Creates a new node, returning a pointer to a stack allocated object
template <typename T>
LinkedListNode<T>* LinkedListNode<T>::create(T value, LinkedListNode<T>* next) {
return new LinkedListNode(value, next);
}
} }
} }

View File

@ -4,12 +4,14 @@
namespace Datastructures { namespace Datastructures {
namespace Nodes { namespace Nodes {
template <typename T> template <typename T>
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode> class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
{ {
public: public:
LinkedListNode(); LinkedListNode(T value, LinkedListNode<T>* next = nullptr);
~LinkedListNode(); ~LinkedListNode();
LinkedListNode* create(T value, LinkedListNode<T>* next = nullptr);
private: private:
}; };