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 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user