-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_node.h
More file actions
49 lines (40 loc) · 1.18 KB
/
tree_node.h
File metadata and controls
49 lines (40 loc) · 1.18 KB
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
44
45
46
47
48
49
#ifndef BINARY_SEARCH_TREE_TREE_NODE_H
#define BINARY_SEARCH_TREE_TREE_NODE_H
#include <vector>
#include <string>
template <class K, class V>
class tree_node {
public:
K key;
V value;
tree_node<K, V>* left;
tree_node<K, V>* right;
tree_node<K, V>* parent;
explicit tree_node(
K k,
V v,
tree_node<K, V>* l = nullptr,
tree_node<K, V>* r = nullptr,
tree_node<K, V>* p = nullptr
) : key(k), left(l), right(r), parent(p), value(v) { }
bool operator<(const tree_node<K, V> &rhs) const {
return key < rhs.key;
}
template <class K1, class V1>
friend std::ostream &operator<<(std::ostream &os, const tree_node<K1, V1>& treeNode);
};
template <class K, class V>
std::ostream &operator<<(std::ostream &os, const tree_node<K, V>& node) {
os << "{" << node.key << ": " << node.value << "};";
return os;
}
template <class K, class V2>
std::ostream &operator<<(std::ostream &os, const tree_node<K, std::vector<V2>>& node) {
os << "\n" << node.key << ": [ ";
for (auto v: node.value) {
os << v << ", ";
}
os << "]";
return os;
}
#endif //BINARY_SEARCH_TREE_TREE_NODE_H