-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalance_tree.cpp
More file actions
85 lines (66 loc) · 1.72 KB
/
balance_tree.cpp
File metadata and controls
85 lines (66 loc) · 1.72 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
#include "tree.h"
int main()
{
setlocale(0, "");
int d = 0;
char ch;
int b = 0;
tree* root;
root = NULL;
int dip, count;
int tell;
srand(time(NULL));
cout << "Заполнить дерево случаными числами?" << endl;
cout << "1. Да" << endl;
cout << "2. Нет" << endl;
cout << endl;
cin >> tell;
switch (tell)
{
case 1:
cout << "Введите диапозон значений: ";
cin >> dip;
cout << "Введите количество элементов: ";
cin >> count;
cout << endl;
try {
if ((count != 0) && (dip != 0)) {
throw dip;
}
cout << "Введено нулевое значение" << endl;
return 1;
}
catch (int e) {
do {
d = rand() % abs(e);
root->Insert(root, d);
b += 1;
} while (b != abs(count));
}
break;
case 2:
break;
default:
cout << "Ошибка! Повторите попытку.";
return 1;
}
cout << " Заполнение дерева вручную:" << endl;
do {
cout << endl;
cout << "Введите число: ";
cin >> d;
cout << endl;
root->Insert(root, d);
cout << "Продолжить ввод чисел? (y/n) ";
cin >> ch;
} while (ch != 'n');
cout << endl;
root->Print(root);
root->Clear(&root);
if (!root) {
cout << "Дерево успешно очищено!" << endl;
}
else {
cout << "Ошибка удаления!" << endl;
}
}