-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.hpp
43 lines (36 loc) · 870 Bytes
/
node.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// node.hpp
#pragma once
#include <vector>
template <typename T>
class Node {
public:
Node(const T &value);
const T &getValue() const;
void addChild(Node<T> *child);
const std::vector<Node<T> *> &getChildren() const;
bool operator==(Node<T> &other) const;
private:
T value;
std::vector<Node<T> *> children;
};
// Definitions in header file
template <typename T>
Node<T>::Node(const T &value) : value(value) {}
template <typename T>
const T &Node<T>::getValue() const {
return value;
}
template <typename T>
void Node<T>::addChild(Node<T> *child) {
if(child == nullptr) { return; }
children.push_back(child);
}
template <typename T>
const std::vector<Node<T> *> &Node<T>::getChildren() const {
return children;
}
template <typename T>
inline bool Node<T>::operator==(Node<T> &other) const
{
return this == &other;
}