-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
298 lines (281 loc) · 6.06 KB
/
main.cpp
File metadata and controls
298 lines (281 loc) · 6.06 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "graph.h"
#include <windows.h>
#include <conio.h>
using namespace std;
void Print(const string& text) {
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(consoleHandle, &bufferInfo);
int screenWidth = bufferInfo.srWindow.Right - bufferInfo.srWindow.Left + 1;
int textWidth = static_cast<int>(text.size());
int leftMargin = (screenWidth - textWidth) / 2;
cout << string(leftMargin, ' ') << text;
}
template <typename T>
T check()
{
T value;
while (!(cin >> value) || (cin.peek() != '\n'))
{
cin.clear();
while (cin.get() != '\n')
{
system("cls");
Print("Ââåäèòå êîððåêòíûå äàííûå: ");
}
}
return value;
}
void next() {
Print("Íàæìèòå ëþáóþ êíîïêó, ÷òîáû ïðîäîëæèòü\n");
_getch();
}
template <typename V>
vector<V> selection_pair() {
Print("Âûáîð ïàðû âåðøèí\n");
Print("Ââåäèòå èìÿ âåðøèíû (îòêóäà): ");
V v_from = check<V>();
Print("Ââåäèòå èìÿ âåðøèíû (êóäà): ");
V v_to = check<V>();
vector<V> result;
result.push_back(v_from);
result.push_back(v_to);
return result;
}
template <typename V, typename D>
void Edd_vertex(Graph<V, D>& G) {
system("cls");
Print("Ââåäèòå èìÿ âåðøèíû, êîòîðóþ õîòåòå äîáàâèòü: ");
V v = check<V>();
try {
G.add_V(v);
Print("Âåðøèíà óñïåøíî äîáàâëåíà\n");
}
catch (const char* ex) {
Print(ex);
}
next();
}
template <typename V, typename D>
void Edd_edge(Graph<V, D>& G) {
if (G.size_g() < 2) { return; }
system("cls");
Print("Ââåäèòå âåñ ðåáðà: ");
D d = check<D>();
vector<V> pair = selection_pair<V>();
try {
G.add_E(pair[0], pair[1], d);
Print("Ðåáðî óñïåøíî ïðîâåäåíî\n");
}
catch (const char* ex) {
Print(ex);
}
next();
}
template <typename V, typename D>
void delete_V(Graph<V, D>& G) {
if (G.size_g() < 1) { return; }
system("cls");
Print("Ââåäèòå èìÿ âåðøèíû: ");
V v = check<V>();
try {
G.delete_V(v);
Print("Âåðøèíà óäàëåíà\n");
}
catch (const char* ex) {
Print(ex);
}
next();
}
template <typename V, typename D>
void delete_E(Graph<V, D>& G) {
if (G.size_g() < 2) { return; }
system("cls");
vector<V> pair = selection_pair<V>();
try {
G.delete_E(pair[0], pair[1]);
}
catch (const char* ex) {
Print(ex);
}
}
template <typename V, typename D>
void deep_walk(Graph<V, D>& G) {
if (G.size_g() < 1) { return; }
system("cls");
Print("Ââåäèòå ñòðòîâóþ òî÷êó äëÿ îáõîäà â ãëóáèíó: ");
V v = check<V>();
try {
vector<V> result = G.deep_cool(v);
Print("Îáõîä â ãëóáèíó:\n");
for (int i = 0; i < result.size(); i++) {
cout << "\t\t\t\t\t" << result[i] << endl;
}
}
catch (const char* ex) {
Print(ex);
}
next();
}
template <typename V, typename D>
void min_way(Graph<V, D>& G) {
if (G.size_g() < 2) { return; }
system("cls");
vector<V> pairr = selection_pair<V>();
try {
pair<vector<V>, D> p = G.belman_ford(pairr[0], pairr[1]);
Print("Âåñ êðàò÷àéøåãî ïóòè - ");
cout << p.second << endl;
Print("Ïóòü :\n");
vector<V> result = p.first;
for (int i = 0; i < result.size(); i++) {
cout << "\t\t\t\t\t\t\t" << result[i] << endl;
}
}
catch (const char* ex) {
Print(ex);
}
next();
}
int menu_1() {
while (true) {
system("cls");
Print("\n\n\n\n\n");
Print("Äîáàâèòü âåðøèíó - [ 1 ]\n");
Print("Äîáàâèòü ðåáðî - [ 2 ]\n");
Print("Óäàëèòü âåðøèíó - [ 3 ]\n");
Print("Óäàëèòü ðåáðî - [ 4 ]\n");
Print("Îáõîä â ãëóáèíó - [ 5 ]\n");
Print("Íàéòè ìèí ïóòü - [ 6 ]\n");
Print("Ëó÷øåå ìåñòî äëÿ ñêëàäà - [ 7 ]\n");
Print("Âèçóàëèçàöèÿ ãðàôà - [ 8 ]\n");
Print("Î÷èñòèòü ãðàô - [ 9 ]\n\n");
Print("Íàçàä - [esc]");
int key = _getch();
if (key == 49 || key == 50 || key == 51 || key == 52 || key == 53 || key == 54 || key == 55 || key == 56 || key == 57 || key == 27) { return key; }
}
}
template <typename V, typename D>
void good_stor(Graph<V, D> G) {
if (G.size_g() < 2) { return; }
system("cls");
try {
V name_store = G.good_place();
Print("Ëó÷øåå ìåñòî äëÿ ñêëàäà:\n");
cout << "\t\t\t\t\t\t\t " << name_store << endl;
}
catch (const char* ex) {
Print(ex);
}
next();
}
void ready_graph(Graph<int, int>& G) {
G.clean();
G.add_V(1);
G.add_V(2);
G.add_V(3);
G.add_V(4);
G.add_V(5);
G.add_V(6);
G.add_V(7);
G.add_V(8);
G.add_E(1, 2, 30);
G.add_E(1, 4, 5);
G.add_E(1, 3, 20);
G.add_E(4, 3, 12);
G.add_E(2, 5, 2);
G.add_E(2, 6, 12);
G.add_E(3, 5, 16);
G.add_E(3, 8, 60);
G.add_E(6, 8, 40);
G.add_E(5, 7, 4);
G.add_E(7, 8, 21);
}
template <typename V, typename D>
void main_menu() {
Graph<V, D> G;
Graph<int, int> G1;
menu:
int key = menu_1();
switch (key) {
case 49:
Edd_vertex<V, D>(G);
goto menu;
case 50:
Edd_edge<V, D>(G);
goto menu;
case 51:
delete_V<V, D>(G);
goto menu;
case 52:
delete_E<V, D>(G);
goto menu;
case 53:
deep_walk<V, D>(G);
goto menu;
case 54:
min_way<V, D>(G);
goto menu;
case 55:
good_stor<V, D>(G);
goto menu;
case 56:
G.visualizeGraph();
goto menu;
case 57:
//
goto menu;
case 27:
return;
}
}
int selection_menu() {
here:
while (true) {
system("cls");
Print("\n\n\n\n\n");
Print("Âûáðàòü òèï äàííûõ âåðøèíà è âåñ ðåáðà\n");
Print("Ðåáðî - int, âåñ - int: [ 1 ] \n");
Print("Ðåáðî - string, âåñ - int: [ 2 ] \n");
Print("Ðåáðî - char, âåñ - int: [ 3 ] \n");
Print("Ðåáðî - double, âåñ - int: [ 4 ] \n");
Print("Ðåáðî - int, âåñ - double: [ 5 ]\n");
Print("Ðåáðî - string, âåñ - double: [ 6 ]\n");
Print("Ðåáðî - char, âåñ - double: [ 7 ]\n");
Print(" Ðåáðî - double, âåñ - double: [ 8 ]\n\n");
Print("Âûõîä - [esc]");
int key = _getch();
switch (key)
{
case(49):
main_menu<int, int>();
goto here;
case(50):
main_menu<string, int>();
case(51):
main_menu<char, int>();
goto here;
case(52):
main_menu<double, int>();
goto here;
case(53):
main_menu<int, double>();
goto here;
case(54):
main_menu<string, double>();
goto here;
case(55):
main_menu<char, double>();
goto here;
case(56):
main_menu<double, double>();
goto here;
case(27):
return -1;
}
}
}
int main() {
setlocale(LC_ALL, "rus");
selection_menu();
}