-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (47 loc) · 1.29 KB
/
Copy pathmain.cpp
File metadata and controls
63 lines (47 loc) · 1.29 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
#include <iostream> // cout
#include <cmath> // pow
#include "binary_search_tree.hpp"
#include "traversal_algorithm.hpp"
using namespace itis;
int main(int argc, char** argv) {
/*
* 8
* 3 10
* 1 6 x 14
* x x 4 7 x x 13 x
*
* x - это nullptr
*/
BinarySearchTree tree;
tree.Insert(8);
tree.Insert(3);
tree.Insert(10);
tree.Insert(1);
tree.Insert(6);
tree.Insert(4);
tree.Insert(7);
tree.Insert(14);
tree.Insert(13);
// tree.Remove(4);
// tree.Remove(6);
// tree.Remove(8);
// обход узлов дерева в порядке неубывания ключей
TraversalAlgorithm* algorithm = new InOrderTraversalAlgorithm;
std::cout << "In-order (LNR): ";
tree.Traverse(*algorithm);
std::cout << std::endl;
algorithm = new PreOrderTraversalAlgorithm;
std::cout << "Pre-order (NLR): ";
tree.Traverse(*algorithm);
std::cout << std::endl;
algorithm = new PostOrderTraversalAlgorithm;
std::cout << "Post-order (LRN): ";
tree.Traverse(*algorithm);
std::cout << std::endl;
algorithm = new BreadthFirstTraversalAlgorithm;
std::cout << "Level-order (BFS): ";
tree.Traverse(*algorithm);
std::cout << std::endl;
delete algorithm;
return 0;
}