-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfl_node.h
61 lines (50 loc) · 1.29 KB
/
fl_node.h
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
50
51
52
53
54
55
56
57
58
59
60
61
//
// Created by ux on 08.12.21.
//
#ifndef FL_REVERSING_FL_NODE_H
#define FL_REVERSING_FL_NODE_H
#include <memory>
/**
* Templated node for a single linked (forward) list.
*
* @tparam T
*/
template <typename T>
struct FLNode{
explicit FLNode(T value) {
this->value = value;
std::shared_ptr<FLNode<T>> empty(nullptr);
this->next = empty;
}
FLNode(std::initializer_list<T> list) {
std::shared_ptr<FLNode<T>> empty(nullptr);
//I can't use the head as a shared pointer because of the 'this'.
FLNode<T> * head = nullptr;
for (T node: list) {
if (nullptr == head) {
this->value = node;
this->next = empty;
head = this;
} else {
head->next = std::make_shared<FLNode<T>>(node);
head = head->next.get();
}
}
}
FLNode(FLNode & node) {
this->value = node.value;
this->next = node.next;
}
FLNode(FLNode && node) {
this->value = node.value;
this->next = std::move(node.next);
}
~FLNode() {
/*
std::cout << "destruct: " << this->value << std::endl;
*/
}
T value;
std::shared_ptr<FLNode<T>> next;
};
#endif //FL_REVERSING_FL_NODE_H