-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVLTreeMenu.cpp
More file actions
108 lines (97 loc) · 1.8 KB
/
AVLTreeMenu.cpp
File metadata and controls
108 lines (97 loc) · 1.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "AVLTreeMenu.h"
#include "Common.h"
void AVLTreeMenu(AVLTree* tree)
{
enum class Menu
{
Add = 1,
Remove = 2,
Find = 3,
Exit = 0
};
InitTree(tree);
bool endProgramm = false;
while (!endProgramm)
{
std::cout << "Here is AVL-tree:" << std::endl;
ShowTree(tree->RootNode, 3);
std::cout << "\n1 - Add\n"
<< "2 - Remove\n"
<< "3 - Find\n"
<< "0 - Exit\n"
<< std::endl;
int userChoose = GetValue();
switch (static_cast<Menu>(userChoose))
{
case Menu::Add:
{
tree->RootNode = Insert(tree->RootNode, GetValue());
break;
}
case Menu::Remove:
{
int key = GetValue();
if (Find(tree->RootNode, key) == nullptr)
{
std::cout << "Not found (" << std::endl;
system("pause");
break;
}
tree->RootNode = Remove(tree->RootNode, key);
break;
}
case Menu::Find:
{
int key = GetValue();
if (Find(tree->RootNode, key) == nullptr)
{
std::cout << "Not found (" << std::endl;
system("pause");
break;
}
std::cout << "Node with value " << key
<< " has address: "
<< Find(tree->RootNode, key) << std::endl;;
system("pause");
break;
}
case Menu::Exit:
{
endProgramm = true;
break;
}
default:
{
std::cout << "Unknown command. Choose one from the list" << std::endl;
system("pause");
break;
}
}
system("cls");
}
}
void ShowTree(AVLNode* treeNode, int indent)
{
if (treeNode == nullptr)
{
return;
}
if (treeNode->RightNode)
{
ShowTree(treeNode->RightNode, indent + 4);
}
if (indent)
{
std::cout << std::setw(indent) << ' ';
}
if (treeNode->RightNode)
{
std::cout << " /\n" << std::setw(indent) << ' ';
}
std::cout << treeNode->Key << "\n ";
if (treeNode->LeftNode)
{
std::cout << std::setw(indent) << ' ' << " \\\n";
ShowTree(treeNode->LeftNode, indent + 4);
}
}