-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.cpp
More file actions
613 lines (592 loc) · 24 KB
/
Copy pathInterface.cpp
File metadata and controls
613 lines (592 loc) · 24 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#include "Interface.h"
void beginInterface(){
bool programFinished = false;
size_t choice;
while(!programFinished){
std::cout<<"\nWelcome..\n";
std::cout<<"Do you want to make a tree or a graph?\n";
std::cout<<"If you want to make a tree you need to type in 1.\n";
std::cout<<"If you want to make a graph you need to type in 2.\n";
std::cout<<"1) tree\n";
std::cout<<"2) graph\n";
std::cout<<"3) quit\n";
std::cin>>choice;
switch(choice){
case 1:{
bool treeIsFinished = false;
while(!treeIsFinished){
size_t treeChoice;
std::cout<<"\nWhat type of tree do you want to create?\n";
std::cout<<"1) Empty tree.\n";
std::cout<<"2) Tree with root.\n";
std::cout<<"3) Tree with leaves.\n";
std::cout<<"4) Exit.\n";
std::cin>>treeChoice;
switch(treeChoice){
case 1:{
TreeList<int> tree_0;
size_t action;
bool finished = false;
while(!finished){
std::cout<<"\nWhat would you like to do?\n";
std::cout<<"1) Add node to the tree.\n";
std::cout<<"2) Delete all nodes from the Tree.\n";
std::cout<<"3) Check if a number exists in the Tree using BFS.\n";
std::cout<<"4) Check if a number exists in the Tree using DFS.\n";
std::cout<<"5) Check if the tree is empty.\n";
std::cout<<"6) Print the tree.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
std::cout<<"\n";
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the tree?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the tree).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the tree).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
tree_0.add(m_data, m_parent);
break;
}
case 2:{
tree_0.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_0.BFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_0.DFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 5:{
if(tree_0.empty()){
std::cout<<"The tree is empty.\n";
break;
}
std::cout<<"The tree is not empty.\n";
break;
}
case 6:{
tree_0.traverse();
std::cout<<"\n";
break;
}
case 7:{
tree_0.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 2:{
int rootData;
std::cout<<"\nPlease type the integer value you want for the root:\n";
std::cin>>rootData;
TreeList<int> tree_1(rootData);
size_t action;
bool finished = false;
while(!finished){
std::cout<<"What would you like to do?\n";
std::cout<<"1) Add node to the tree.\n";
std::cout<<"2) Delete all nodes from the Tree.\n";
std::cout<<"3) Check if a number exists in the Tree using BFS.\n";
std::cout<<"4) Check if a number exists in the Tree using DFS.\n";
std::cout<<"5) Check if the tree is empty.\n";
std::cout<<"6) Print the tree.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
std::cout<<"\n";
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the tree?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the tree).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the tree).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
tree_1.add(m_data, m_parent);
break;
}
case 2:{
tree_1.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_1.BFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_1.DFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 5:{
if(tree_1.empty()){
std::cout<<"The tree is empty.\n";
break;
}
std::cout<<"The tree is not empty.\n";
break;
}
case 6:{
tree_1.traverse();
std::cout<<"\n";
break;
}
case 7:{
tree_1.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 3:{
int rootData;
size_t arraySize;
std::cout<<"\nPlease type the integer value you want for the root:\n";
std::cin>>rootData;
std::cout<<"Please enter the size of the array and the values:\n";
std::cout<<"size: ";
std::cin>>arraySize;
int arrayValues[arraySize];
for(size_t i = 0; i < arraySize; i++){
std::cout<<"Write an integer value: ";
std::cin>>arrayValues[i];
std::cout<<"\n";
}
std::cout<<"\n";
TreeList<int> tree_2(rootData, arrayValues, arraySize);
size_t action;
bool finished = false;
while(!finished){
std::cout<<"\nWhat would you like to do?\n";
std::cout<<"1) Add node to the tree.\n";
std::cout<<"2) Delete all nodes from the Tree.\n";
std::cout<<"3) Check if a number exists in the Tree using BFS.\n";
std::cout<<"4) Check if a number exists in the Tree using DFS.\n";
std::cout<<"5) Check if the tree is empty.\n";
std::cout<<"6) Print the tree.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the tree?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the tree).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the tree).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
tree_2.add(m_data, m_parent);
break;
}
case 2:{
tree_2.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_2.BFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the tree: \n";
std::cin>>searchNum;
if(tree_2.DFS(searchNum)){
std::cout<<"The number exists in the tree.\n";
break;
}
std::cout<<"The number doesn't exist in the tree.\n";
break;
}
case 5:{
if(tree_2.empty()){
std::cout<<"The tree is empty.\n";
break;
}
std::cout<<"The tree is not empty.\n";
break;
}
case 6:{
tree_2.traverse();
std::cout<<"\n";
break;
}
case 7:{
tree_2.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 4:{
treeIsFinished = true;
break;
}
default: std::cout<<"Esta entrada no es válida. Intente de nuevo.\n";
}
}
break;
}
case 2:{
bool graphIsFinished = false;
while(!graphIsFinished){
size_t graphChoice;
std::cout<<"\nWhat type of graph do you want to create?\n";
std::cout<<"1) Empty graph.\n";
std::cout<<"2) Graph with root.\n";
std::cout<<"3) Graph with leaves.\n";
std::cout<<"4) Exit.\n";
std::cin>>graphChoice;
switch(graphChoice){
case 1:{
Graph<int> graph_0;
size_t action;
bool finished = false;
while(!finished){
std::cout<<"\nWhat would you like to do?\n";
std::cout<<"1) Add node to the graph.\n";
std::cout<<"2) Delete all nodes from the graph.\n";
std::cout<<"3) Check if a number exists in the graph using BFS.\n";
std::cout<<"4) Check if a number exists in the graph using DFS.\n";
std::cout<<"5) Check if the graph is empty.\n";
std::cout<<"6) Print the graph.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
std::cout<<"\n";
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the graph?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the tree).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the tree).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
graph_0.add(m_data, m_parent);
break;
}
case 2:{
graph_0.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_0.BFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_0.DFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 5:{
if(graph_0.empty()){
std::cout<<"The graph is empty.\n";
break;
}
std::cout<<"The graph is not empty.\n";
break;
}
case 6:{
graph_0.traverse();
std::cout<<"\n";
break;
}
case 7:{
graph_0.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 2:{
int rootData;
std::cout<<"\nPlease type the integer value you want for the root:\n";
std::cin>>rootData;
Graph<int> graph_1(rootData);
size_t action;
bool finished = false;
while(!finished){
std::cout<<"\nWhat would you like to do?\n";
std::cout<<"1) Add node to the graph.\n";
std::cout<<"2) Delete all nodes from the graph.\n";
std::cout<<"3) Check if a number exists in the graph using BFS.\n";
std::cout<<"4) Check if a number exists in the graph using DFS.\n";
std::cout<<"5) Check if the graph is empty.\n";
std::cout<<"6) Print the graph.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
std::cout<<"\n";
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the graph?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the graph).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the graph).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
graph_1.add(m_data, m_parent);
break;
}
case 2:{
graph_1.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_1.BFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_1.DFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 5:{
if(graph_1.empty()){
std::cout<<"The graph is empty.\n";
break;
}
std::cout<<"The graph is not empty.\n";
break;
}
case 6:{
graph_1.traverse();
std::cout<<"\n";
break;
}
case 7:{
graph_1.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 3:{
int rootData;
size_t arraySize;
std::cout<<"\nPlease type the integer value you want for the root:\n";
std::cin>>rootData;
std::cout<<"Please enter the size of the array and the values:\n";
std::cout<<"size: ";
std::cin>>arraySize;
int arrayValues[arraySize];
for(size_t i = 0; i < arraySize; i++){
std::cout<<"Write an integer value: ";
std::cin>>arrayValues[i];
std::cout<<"\n";
}
Graph<int> graph_2(rootData, arrayValues, arraySize);
size_t action;
bool finished = false;
while(!finished){
std::cout<<"\nWhat would you like to do?\n";
std::cout<<"1) Add node to the graph.\n";
std::cout<<"2) Delete all nodes from the graph.\n";
std::cout<<"3) Check if a number exists in the graph using BFS.\n";
std::cout<<"4) Check if a number exists in the graph using DFS.\n";
std::cout<<"5) Check if the graph is empty.\n";
std::cout<<"6) Print the graph.\n";
std::cout<<"7) Exit.\n";
std::cin>>action;
std::cout<<"\n";
//Interface<TreeList<int>> interfaceTree;
//interfaceTree.begin();
switch(action){
case 1:{
int m_data;
int m_parent;
std::cout<<"\nWhat integer value do you want to add to the graph?\n";
std::cout<<"You have to pass in two different parameters: \n";
std::cout<<"Data: (Interger number you to pass into the graph).\n";
std::cout<<"Parent: (Integer number that will be the parent of the data you are pushing into the graph).\n";
std::cout<<"Data: ";
std::cin>>m_data;
std::cout<<"\n";
std::cout<<"Parent: ";
std::cin>>m_parent;
graph_2.add(m_data, m_parent);
break;
}
case 2:{
graph_2.clear();
std::cout<<"All nodes were deleted.\n";
break;
}
case 3:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_2.BFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 4:{
int searchNum;
std::cout<<"\nWhich number do you want to find in the graph: \n";
std::cin>>searchNum;
if(graph_2.DFS(searchNum)){
std::cout<<"The number exists in the graph.\n";
break;
}
std::cout<<"The number doesn't exist in the graph.\n";
break;
}
case 5:{
if(graph_2.empty()){
std::cout<<"The graph is empty.\n";
break;
}
std::cout<<"The graph is not empty.\n";
break;
}
case 6:{
graph_2.traverse();
std::cout<<"\n";
break;
}
case 7:{
graph_2.clear();
finished = true;
break;
}
default: std::cout<<"Incorrect Input. Try Again.\n";
}
}
break;
}
case 4:{
graphIsFinished = true;
break;
}
}
}
break;
}
case 3:{
programFinished = true;
break;
}
default: std::cout<<"Esta entrada no es válida. Intente de nuevo.\n";
}
}
std::cout<<"Good bye.\n";
}