-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
97 lines (95 loc) · 2.16 KB
/
main.cpp
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
#include "main.h"
#include "input.h"
#include "avlTree.cpp"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
printMainMenu();
AvlTree avlTree;
int selection;
int input;
string nodeInfo;
vector<int> arrayOfValues;
do
{
selection = getMainMenuInput();
switch (selection)
{
case CREATE_TREE:
arrayOfValues = getFileInput();
avlTree.createTree(arrayOfValues);
cout << "Create Tree:";
avlTree.preOrderPrint();
cout << endl;
break;
case INSERTION:
cout << "Enter the Integer Value to Insert.\n";
input = getIntInput();
avlTree.insert(input);
cout << "Inserted:";
avlTree.preOrderPrint();
cout << endl;
break;
case DELETION:
cout << "Enter the Integer Value to Delete.\n";
input = getIntInput();
if(!avlTree.remove(input))
cout << "Node cannot be deleted. Empty Tree!\n";
else
{
cout << "Deleted:";
avlTree.preOrderPrint();
cout << endl;
}
break;
case SEARCH:
cout << "Enter the Integer Value to Search.\n";
nodeInfo = avlTree.search(getIntInput());
if (nodeInfo.empty())
cout << "Value Not Found.\n";
else
cout << "Node Found:" << nodeInfo;
break;
case TRAVERSAL:
printTraversalMenu();
input = getTravMenuInput();
switch (input)
{
case PREORDER:
cout << "Pre-Order Traversal:";
avlTree.preOrderPrint();
cout << endl;
break;
case POSTORDER:
cout << "Post-Order Traversal:";
avlTree.postOrderPrint();
cout << endl;
break;
case INORDER:
cout << "In-Order Traversal:";
avlTree.inOrderPrint();
cout << endl;
break;
}
break;
case DELETE_TREE:
if (avlTree.delete_tree())
cout << "Delete Tree: Tree Deleted\n";
else
cout << "Delete Tree: Tree Does Not Exist\n";
break;
case CHECK_BALANCE:
input = avlTree.check_balance();
if (input < 0)
cout << "No Balance Factor. Empty Tree!\n";
else
cout << "Check Balance: " << input << endl;
break;
}
if (selection != EXIT)
cout << "Make Another Selection from the Main Menu.\n";
} while (selection != EXIT);
}