Updated Linked List Node to work with shared pointers

This commit is contained in:
Luke Else 2022-11-07 14:14:49 +00:00
parent 2da0705577
commit 5913fb8084
2 changed files with 6 additions and 6 deletions

View File

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

View File

@ -7,10 +7,10 @@ namespace Datastructures {
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
{
public:
LinkedListNode(T value, LinkedListNode<T>* next = nullptr);
LinkedListNode(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
~LinkedListNode();
LinkedListNode* create(T value, LinkedListNode<T>* next = nullptr);
std::shared_ptr<LinkedListNode<T>> create(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
private: