-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.tpp
55 lines (48 loc) · 1.16 KB
/
Node.tpp
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
//
// Created by Hassan Attar on 2024-01-25.
//
#include "Node.h"
template<typename T>
Node<T>::Node(const T &data): Node(data, 0) {}
template<typename T>
Node<T>::Node(const T &data, int _level): next{new Node<T>*[_level + 1]}, level{_level}, data{data} {}
template<typename T>
Node<T>::~Node() {
if(next){
delete [] next;
}
}
template<typename T>
Node<T>::Node(const Node<T> &rhs): Node(rhs.data, rhs.level) {
for(int i = 0; i <= level; i++){
next[i] = rhs.next[i];
}
}
template<typename T>
Node<T> &Node<T>::operator=(const Node<T> &rhs) {
if(this != &rhs){
if(next){
delete [] next;
}
level = rhs.level;
data = rhs.data;
next = new Node<T>*[level + 1];
for(int i = 0; i <= level; i++){
next[i] = rhs.next[i];
}
}
}
template<typename T>
Node<T>::Node(Node<T> &&rhs) noexcept: next{rhs.next}, level{rhs.level}, data{rhs.data} {
rhs.next = nullptr;
}
template<typename T>
Node<T> &Node<T>::operator=(Node<T> &&rhs) {
if(next){
delete [] next;
}
next = rhs.next;
data = rhs.data;
level = rhs.level;
rhs.next = nullptr;
}