From 5913fb80847c22bb9168e053a4523b81e6a004ac Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 7 Nov 2022 14:14:49 +0000 Subject: [PATCH] Updated Linked List Node to work with shared pointers --- DataStructures/src/LinkedList/linkedlistnode.cpp | 8 ++++---- DataStructures/src/LinkedList/linkedlistnode.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DataStructures/src/LinkedList/linkedlistnode.cpp b/DataStructures/src/LinkedList/linkedlistnode.cpp index d0d8468..e8e6d2e 100644 --- a/DataStructures/src/LinkedList/linkedlistnode.cpp +++ b/DataStructures/src/LinkedList/linkedlistnode.cpp @@ -3,15 +3,15 @@ namespace Datastructures { namespace Nodes { template - LinkedListNode::LinkedListNode(T value, LinkedListNode* next) { + LinkedListNode::LinkedListNode(T value, std::shared_ptr> 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 - LinkedListNode* LinkedListNode::create(T value, LinkedListNode* next) { - return new LinkedListNode(value, next); + std::shared_ptr> LinkedListNode::create(T value, std::shared_ptr> next) { + return std::make_shared>(value, next); } } } \ No newline at end of file diff --git a/DataStructures/src/LinkedList/linkedlistnode.h b/DataStructures/src/LinkedList/linkedlistnode.h index dd9175c..1e9b3a0 100644 --- a/DataStructures/src/LinkedList/linkedlistnode.h +++ b/DataStructures/src/LinkedList/linkedlistnode.h @@ -7,10 +7,10 @@ namespace Datastructures { class LinkedListNode : public Generic::UndirectedNode> { public: - LinkedListNode(T value, LinkedListNode* next = nullptr); + LinkedListNode(T value, std::shared_ptr> next = nullptr); ~LinkedListNode(); - LinkedListNode* create(T value, LinkedListNode* next = nullptr); + std::shared_ptr> create(T value, std::shared_ptr> next = nullptr); private: