-
Notifications
You must be signed in to change notification settings - Fork 0
/
aisd_lab1.cpp
96 lines (73 loc) · 2.93 KB
/
aisd_lab1.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
#include <iostream>
#include "taskHost.h"
#include "list_array.h"
#include "list_chain.h"
#include "list_node.h"
#include "basic_list.h"
int main()
{
srand(rand());
std::cout << "Hello World!\n";
std::cout << "Enter size of array: ";
int tempInt = 0;
std::cin >> tempInt;
list_array* array = new list_array();
list_chain* chain = new list_chain();
for (int i(0); i < tempInt; i++) {
array->append(new list_node_array(rand() % 12));
chain->append(new list_node_chain(rand() % 12));
}
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
std::cout << std::endl << "==== \t Appending \t ====" << std::endl;
std::cout << "Enter value to append: ";
std::cin >> tempInt;
array->append(new list_node_array(tempInt));
chain->append(new list_node_chain(tempInt));
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
std::cout << std::endl << "==== \t Delete at position \t ====" << std::endl;
std::cout << "Enter index: ";
std::cin >> tempInt;
array->remove(tempInt);
chain->remove(tempInt);
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
std::cout << std::endl << "==== \t Insert after \t ====" << std::endl;
std::cout << "Enter index: ";
std::cin >> tempInt;
int value = 0;
std::cout << "Enter value: ";
std::cin >> value;
array->insert(new list_node_array(value) , tempInt);
chain->insert(new list_node_chain(value), tempInt);
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
std::cout << std::endl << "==== \t Sorting \t ====" << std::endl;
array->sort();
chain->sort();
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
//std::cout << std::endl << "==== \t TASK _1 \t ====" << std::endl;
//array->task1();
//chain->task1();
//std::cout << "Array and list: " << std::endl;
//std::cout << "Array: " << array->to_string() << std::endl;
//std::cout << "List: " << chain->to_string() << std::endl;
std::cout << std::endl << "==== \t DEFENCE \t ====" << std::endl;
try {
array->defence();
chain->defence();
std::cout << "Array and list: " << std::endl;
std::cout << "Array: " << array->to_string() << std::endl;
std::cout << "List: " << chain->to_string() << std::endl;
}
catch (std::exception& ex) {
std::cout << ex.what();
}
}