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,7 +1,7 @@
#include "undirectednode.h"
namespace Generic {
template<typename T, typename NodeType>
template <typename T, typename NodeType>
UndirectedNode<T, NodeType>::UndirectedNode(T value, NodeType* left, NodeType* right){
this->value = value;
this->next = next;

View File

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

View File

@ -2,6 +2,16 @@
namespace Datastructures {
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 Nodes {
template <typename T>
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode>
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
{
public:
LinkedListNode();
LinkedListNode(T value, LinkedListNode<T>* next = nullptr);
~LinkedListNode();
LinkedListNode* create(T value, LinkedListNode<T>* next = nullptr);
private:
};