Updated Generic nodes to incorporate smart pointers
This commit is contained in:
parent
deb58f03bb
commit
2da0705577
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Generic {
|
namespace Generic {
|
||||||
template <typename T, typename NodeType>
|
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->value = value;
|
||||||
this->left = left;
|
this->left = left;
|
||||||
this->right = right;
|
this->right = right;
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Generic {
|
namespace Generic {
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
class DirectedNode
|
class DirectedNode
|
||||||
{
|
{
|
||||||
public:
|
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();
|
~DirectedNode();
|
||||||
T value;
|
T value;
|
||||||
NodeType* left;
|
std::shared_ptr<NodeType> left;
|
||||||
NodeType* right;
|
std::shared_ptr<NodeType> right;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Generic {
|
namespace Generic {
|
||||||
template <typename T, typename NodeType>
|
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->value = value;
|
||||||
this->next = next;
|
this->next = next;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Generic {
|
namespace Generic {
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
class UndirectedNode
|
class UndirectedNode
|
||||||
{
|
{
|
||||||
public:
|
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();
|
~UndirectedNode();
|
||||||
T value;
|
T value;
|
||||||
NodeType* next;
|
std::shared_ptr<NodeType> next;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user