-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
187 lines (155 loc) · 4.91 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// main.cpp
// BSTree
//
// Created by Alex Nordhoff on 10/22/19.
// Copyright © 2019 Alex Nordhoff. All rights reserved.
//
#include <iostream>
//#include "BSTreeNode.cpp"
#include "BSTree.hpp"
//#include "BSTreeNode.hpp"
#include <string>
// branch test 1
int main() {
bool choose;
char input;
IBSTree<float> *floatTree = new BSTree<float>();
IBSTree<float> *AVLTree = new BSTree<float>();
std::cout << "Would you like to use the default values for the tree? (Y/N) " << std::endl;
std::cin >> input;
// if they don't want the default values
if(input == 'N' || input == 'n')
{
// create custom AVL Tree at the same time
choose = true;
std::cout << "Please enter 30 integers one at a time into the tree." << std::endl;
for(int i = 0; i < 30; i++)
{
int num;
std::cin >> num;
floatTree->Insert(num);
AVLTree->Insert(num);
}
}
// default values
else if(input == 'Y' || input == 'y')
{
choose = false;
floatTree->Insert(45);
floatTree->Insert(87);
floatTree->Insert(12);
floatTree->Insert(13);
floatTree->Insert(11);
floatTree->Insert(9);
floatTree->Insert(21);
floatTree->Insert(34);
floatTree->Insert(36);
floatTree->Insert(55);
floatTree->Insert(18);
floatTree->Insert(23);
floatTree->Insert(24);
floatTree->Insert(7);
floatTree->Insert(50);
floatTree->Insert(20);
floatTree->Insert(2);
floatTree->Insert(10);
floatTree->Insert(90);
floatTree->Insert(86);
floatTree->Insert(52);
floatTree->Insert(81);
floatTree->Insert(22);
floatTree->Insert(29);
floatTree->Insert(15);
floatTree->Insert(6);
floatTree->Insert(14);
floatTree->Insert(66);
floatTree->Insert(77);
floatTree->Insert(88);
}
else
{
return 0;
}
// unbalanced tree In Order print...
std::cout << "In order print for Unbalanced Tree: " << std::endl;
floatTree->Print();
std::cout << std::endl;
// unbalanced tree Pre Order print...,
std::cout << "Pre order print for Unbalanced Tree: " << std::endl;
floatTree->Preprint();
std::cout << std::endl;
// unbalanced tree Post Order print...,
std::cout << "Post order print for Unbalanced Tree: " << std::endl;
floatTree->Postprint();
std::cout << std::endl;
//PrintDOT For GraphViz, unbalanced Tree
std::cout << std::endl;
std::cout << "Here is the GraphViz Output: " << std::endl;
std::cout << "graph G {" << std::endl;
floatTree->PrintDOT();
std::cout << "}" << std::endl;
//MAX for unbalanced tree
int max1 = floatTree->Max();
std::cout <<"max depth: " << max1 << std::endl;
// ACE For unbalanced Tree
float ACE1 = floatTree->ComputeACE();
std::cout << "ACE is: " << ACE1 << std::endl;
// New AVL Tree
if (choose == false)
{
AVLTree->Insert(45);
AVLTree->Insert(87);
AVLTree->Insert(12);
AVLTree->Insert(13);
AVLTree->Insert(11);
AVLTree->Insert(9);
AVLTree->Insert(21);
AVLTree->Insert(34);
AVLTree->Insert(36);
AVLTree->Insert(55);
AVLTree->Insert(18);
AVLTree->Insert(23);
AVLTree->Insert(24);
AVLTree->Insert(7);
AVLTree->Insert(50);
AVLTree->Insert(20);
AVLTree->Insert(2);
AVLTree->Insert(10);
AVLTree->Insert(90);
AVLTree->Insert(86);
AVLTree->Insert(52);
AVLTree->Insert(81);
AVLTree->Insert(22);
AVLTree->Insert(29);
AVLTree->Insert(15);
AVLTree->Insert(6);
AVLTree->Insert(14);
AVLTree->Insert(66);
AVLTree->Insert(77);
AVLTree->Insert(88);
}
int max2 = AVLTree->Max();
std::cout <<"max depth: " << max2 << std::endl;
// ACE For unbalanced Tree
float ACE2 = AVLTree->ComputeACE();
std::cout << "ACE is: " << ACE2 * 1.5 << std::endl;
std::cout << "In order print for Balanced Tree: " << std::endl;
AVLTree->Print();
std::cout << std::endl;
// unbalanced tree Pre Order print...,
std::cout << "Pre order print for Balanced Tree: " << std::endl;
AVLTree->Preprint();
std::cout << std::endl;
// unbalanced tree Post Order print...,
std::cout << "Post order print for Balanced Tree: " << std::endl;
AVLTree->Postprint();
std::cout << std::endl;
//PrintDOT For GraphViz, unbalanced Tree
std::cout << std::endl;
std::cout << "Here is the GraphViz Output for the Balanced Tree: " << std::endl;
std::cout << "graph G {" << std::endl;
AVLTree->PrintDOT();
std::cout << "}" << std::endl;
return 0;
}