Updated Linked List Node to work with shared pointers
This commit is contained in:
parent
2da0705577
commit
5913fb8084
@ -3,15 +3,15 @@
|
|||||||
namespace Datastructures {
|
namespace Datastructures {
|
||||||
namespace Nodes {
|
namespace Nodes {
|
||||||
template <typename T>
|
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->value = value;
|
||||||
this->next = next;
|
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>
|
template <typename T>
|
||||||
LinkedListNode<T>* LinkedListNode<T>::create(T value, LinkedListNode<T>* next) {
|
std::shared_ptr<LinkedListNode<T>> LinkedListNode<T>::create(T value, std::shared_ptr<LinkedListNode<T>> next) {
|
||||||
return new LinkedListNode(value, next);
|
return std::make_shared<LinkedListNode<T>>(value, next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,10 +7,10 @@ namespace Datastructures {
|
|||||||
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
|
class LinkedListNode : public Generic::UndirectedNode<T, LinkedListNode<T>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LinkedListNode(T value, LinkedListNode<T>* next = nullptr);
|
LinkedListNode(T value, std::shared_ptr<LinkedListNode<T>> next = nullptr);
|
||||||
~LinkedListNode();
|
~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:
|
private:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user