-
Notifications
You must be signed in to change notification settings - Fork 3
/
Node.h
48 lines (44 loc) · 1.23 KB
/
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
//
// Created by Андрей Москалёв on 24.10.2019.
//
#ifndef TREESPRESENTATION_NODE_H
#define TREESPRESENTATION_NODE_H
#include <string>
struct Node {
int key, height, color = 0;
Node * left, * right, * parent;
explicit Node(bool IS_RED = false) {
this->left = this->right = nullptr;
this->color = IS_RED;
}
explicit Node(int k, bool IS_RED = false) {
this->key = k;
this->left = this->right = nullptr;
this->height = 1;
this->color = IS_RED;
}
explicit Node(int k, Node * parent, bool IS_RED = false) {
this->key = k;
this->left = this->right = nullptr;
this->height = 1;
this->color = IS_RED;
}
int treeSize() {
int szL = 0, szR = 0;
if (left != nullptr)
szL = left->treeSize();
if (right != nullptr)
szR = right->treeSize();
return szL + szR + 1;
}
int maxLen() {
int szL = 0, szR = 0;
if (left != nullptr)
szL = left->maxLen();
if (right != nullptr)
szR = right->maxLen();
int sz = std::to_string(key).size();
return std::max(sz, std::max(szL, szR));
}
};
#endif //TREESPRESENTATION_NODE_H