-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarysorttree.cpp
More file actions
69 lines (58 loc) · 1.45 KB
/
Copy pathbinarysorttree.cpp
File metadata and controls
69 lines (58 loc) · 1.45 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
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
#include "binarysorttree.hpp"
#include "node.hpp"
#include "BSTutils.hpp"
BinarySortTree::BinarySortTree(const BinarySortTree& treeToBeCopied)
{
this->rootNode = copy_tree(treeToBeCopied.rootNode);
}
BinarySortTree::BinarySortTree(BinarySortTree&& otherTree)
{
(*this) = std::move(otherTree);
}
BinarySortTree::~BinarySortTree()
{
clear_tree();
}
void BinarySortTree::clear_tree()
{
delete_tree(rootNode);
rootNode=nullptr;
}
void BinarySortTree::insert_value(double value)
{
if(rootNode == nullptr)
{
rootNode = new Node{value};
}
else
{
insert_value_into_tree(rootNode, value);
}
}
std::vector<double> BinarySortTree::get_sorted_values()
{
std::vector<double> sortedVector{get_values_using_inorder_traversal(rootNode)};
return sortedVector;
}
BinarySortTree& BinarySortTree::operator=(const BinarySortTree& otherTree)
{
this->rootNode = copy_tree(otherTree.rootNode);
return *this;
}
BinarySortTree& BinarySortTree::operator=(BinarySortTree&& otherTree)
{
if(this->rootNode != nullptr)
{
clear_tree();
}
this->rootNode = otherTree.rootNode;
otherTree.rootNode = nullptr;
return *this;
}
void BinarySortTree::make_tree_from_vector(const std::vector<double> vectorThatWillBeTree)
{
for (int i = 0; i < vectorThatWillBeTree.size(); i++)
{
insert_value(vectorThatWillBeTree[i]);
}
}