Updated Generic nodes to incorporate smart pointers

This commit is contained in:
Luke Else 2022-11-07 14:08:53 +00:00
parent deb58f03bb
commit 2da0705577
4 changed files with 9 additions and 7 deletions

View File

@ -2,7 +2,7 @@
namespace Generic {
template <typename T, typename NodeType>
DirectedNode<T, NodeType>::DirectedNode(T value, NodeType* left, NodeType* right) {
DirectedNode<T, NodeType>::DirectedNode(T value, std::shared_ptr<NodeType> left, std::shared_ptr<NodeType> right) {
this->value = value;
this->left = left;
this->right = right;

View File

@ -1,15 +1,16 @@
#pragma once
#include <memory>
namespace Generic {
template <typename T, typename NodeType>
class DirectedNode
{
public:
DirectedNode(T value, NodeType* left = nullptr, NodeType* right = nullptr);
DirectedNode(T value, std::shared_ptr<NodeType> left = nullptr, std::shared_ptr<NodeType> right = nullptr);
~DirectedNode();
T value;
NodeType* left;
NodeType* right;
std::shared_ptr<NodeType> left;
std::shared_ptr<NodeType> right;
private:
};

View File

@ -2,7 +2,7 @@
namespace Generic {
template <typename T, typename NodeType>
UndirectedNode<T, NodeType>::UndirectedNode(T value, NodeType* left, NodeType* right){
UndirectedNode<T, NodeType>::UndirectedNode(T value, std::shared_ptr<NodeType> left, std::shared_ptr<NodeType> right){
this->value = value;
this->next = next;
}

View File

@ -1,14 +1,15 @@
#pragma once
#include <memory>
namespace Generic {
template <typename T, typename NodeType>
class UndirectedNode
{
public:
UndirectedNode(T value, NodeType* left = nullptr, NodeType* right = nullptr);
UndirectedNode(T value, std::shared_ptr<NodeType> left = nullptr, std::shared_ptr<NodeType> right = nullptr);
~UndirectedNode();
T value;
NodeType* next;
std::shared_ptr<NodeType> next;
private:
};