-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_cpp.h
69 lines (42 loc) · 1.37 KB
/
tree_cpp.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
62
63
64
65
66
67
68
69
//
// Created by Светлана on 22.03.2019.
//
#ifndef TREE_C_TREE_CPP_H
#define TREE_C_TREE_CPP_H
#include <ostream>
struct Tree {
public:
using TreeValueType = double;
struct Element {
public:
TreeValueType value;
private:
Element(TreeValueType value, Element *head)
: value(value), head(head), depth(0), left(nullptr), right(nullptr) {}
static void Clear(Element *head);
void CalcDepth();
Element *LittleLeftRotate();
Element *LittleRightRotate();
Element *BigLeftRotate();
Element *BigRightRotate();
Element *Insert(TreeValueType new_value);
friend std::ostream &operator<<(std::ostream &os, const Element &element);
static Element *Balancing(Element *head);
const Element *Find(const TreeValueType &value) const;
static Element *Remove(Element *head, TreeValueType value_to_remove);
int depth;
Element *head;
Element *left;
Element *right;
friend Tree;
};
Tree() : root(nullptr) {}
~Tree();
void Insert(TreeValueType value);
const Element *Find(const TreeValueType &value_to_find) const;
void Remove(const TreeValueType &value_to_remove);
friend std::ostream &operator<<(std::ostream &os, const Tree &tree);
private:
Element *root;
};
#endif //TREE_C_TREE_CPP_H