-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (96 loc) · 2.84 KB
/
main.cpp
File metadata and controls
100 lines (96 loc) · 2.84 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
//#include "Tree.h"
#include "Test.h"
using namespace std;
template <class Key, class Data>
Data Data_lrand(Tree<Key,Data> *tree)
{
return rand() << 16 | rand();
}
template<class Key,class Data>
void inputTreeRandom(Tree<Key,Data>* tree, int n) {
for (int i = 0; i < n; i++)
{
Key key = (Key)(rand() % 100);
Data data = (Data)(rand() % 100);
tree->put(key, data);
}
}
template<class Key, class Data>
void menu(Tree<Key,Data>* tree){
int numKey;
bool flagMenu = true;
do {
cout << "Menu:" << endl;
cout << "1 Random generator" << endl;
cout << "2 Add element" << endl;
cout << "3 Remove element" << endl;
cout << "4 Get element" << endl;
cout << "5 Get size of tree" << endl;
cout << "6 Is tree empty?" << endl;
cout << "7 Print of tree" << endl;
cout << "8 Clear of tree" << endl;
cout << "9 Test of labor intensity with random tree" << endl;
cout << "0 Exit" << endl;
cout << "Input command >>";
cin >> numKey;
Key key;
Data data;
int amountElements = 0;
switch (numKey){
case 1:
tree->clear();
cout << "Input amount of elements: ";
cin >> amountElements;
inputTreeRandom(*&tree, amountElements);
break;
case 2:
cout << "Input key: ";
cin >> key;
cout << "Input data: ";
cin >> data;
tree->put(key, data);
break;
case 3:
cout << "Input key:";
cin >> key;
tree->remove(key);
break;
case 4:
cout << "Input key:";
cin >> key;
tree->get(key);
break;
case 5:
cout << "Size of tree: " << tree->getSize() << endl;
break;
case 6:
cout << "Answer: " << tree->isEmpty() << endl;
break;
case 7:
cout << "Output o tree: " << endl;
tree->print();
break;
case 8:
tree->clear();
cout << "Size of tree: " << tree->getSize() << endl;
break;
case 9:
cout << "Input amount of element: ";
cin >> amountElements;
Test::test_randomTree(amountElements);
break;
case 0:
flagMenu = false;
break;
default:
cout << "Repeat please" << endl;
break;
}
}while(flagMenu);
cout << "Done!" <<endl;
};
int main(){
Tree<int, double>* tree = new Tree<int, double>();
menu(*&tree);
return 0;
}