-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin_node_impl.h
More file actions
43 lines (40 loc) · 1.09 KB
/
bin_node_impl.h
File metadata and controls
43 lines (40 loc) · 1.09 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
#include "bin_node.h"
template <typename T>
binNodePos(T) binNode<T>::insertAsLeftChild(T const& data)
{
return left_child_ = new binNode(data, this);
}
template <typename T>
binNodePos(T) binNode<T>::InsertAsRightChild(T const& data)
{
return right_child_ = new binNode(data, this);
}
template <typename T>
int binNode<T>::size()
{
int size = 1;
if (left_child_) {
size += left_child_->size();
}
if (right_child_) {
size += right_child_->size();
}
return size;
}
template <typename T>
binNodePos(T) binNode<T>::succ()
{
binNodePos(T) current_node = this;
if (HasRightChild(*current_node)) { // succ一定是右子树的最左点
current_node = HasRightChild(*current_node);
while(HasLeftChild(*current_node)) {
current_node = HasLeftChild(*current_node);
}
} else { //succ一定是一直往左上追寻到底,再取parent的点
while(IsRightChild(*current_node)) {
current_node = current_node->parent_;
}
current_node = current_node->parent_;
}
return current_node;
}