-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDlab1.cpp
More file actions
118 lines (100 loc) · 2.32 KB
/
Copy pathSDlab1.cpp
File metadata and controls
118 lines (100 loc) · 2.32 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
#include <iostream>
#include <cstdlib>
#include "DynamicArray.h"
using namespace std;
int GetElementConsole();
void ShowArray(DynamicArray* dynamicArray);
int main()
{
DynamicArray* dynamicArray = new DynamicArray;
int count = 0;
int valueForMenu = 0;
int indexForMenu = 0;
for (;;) {
ShowArray(dynamicArray);
cout << "+=================== Dynamic Array ===================+" << endl;
cout << "Length = " << dynamicArray->GetLength() << " Capacity = ";
cout << dynamicArray->GetCapacity() << endl;
cout << "1 - Add Element |";
cout << " 2 - Insert Element | 3 - Remove Element" << endl;
cout << "4 - Line search | 5 - Binary search |";
cout << " 6 - Sort \n=++= ";
cout << " any other button - Exit =++=" << endl;
count = GetElementConsole();
switch (count)
{
case 1:
cout << "Enter a integer value: ";
valueForMenu = GetElementConsole();
dynamicArray->AddElement(valueForMenu);
cout << endl;
break;
case 2:
cout << "Enter index: ";
indexForMenu = GetElementConsole();
cout << endl;
cout << "Value: ";
valueForMenu = GetElementConsole();
dynamicArray->InsertElement(valueForMenu, indexForMenu);
cout << endl;
break;
case 3:
cout << "Enter index: ";
valueForMenu = GetElementConsole();
cout << endl;
dynamicArray->RemoveElement(valueForMenu);
cout << endl;
break;
case 4:
cout << "Enter value: ";
valueForMenu = GetElementConsole();
cout << endl;
cout << dynamicArray->LinearSearch(valueForMenu);
cout << endl;
system("pause");
break;
case 5:
cout << "Enter value: ";
valueForMenu = GetElementConsole();
cout << endl;
cout << dynamicArray->BinarySearch(valueForMenu);
cout << endl;
system("pause");
break;
case 6:
dynamicArray->BubbleSort();
break;
default:
return 0;
}
system("cls");
}
}
int GetElementConsole()
{
while (true)
{
int value;
cin >> value;
if (cin.fail())
{
cin.clear();
cin.ignore(32767, '\n');
cout << "Oops, that input is invalid. Please try again.\n";
}
else
{
cin.ignore(32767, '\n');
return value;
}
}
}
void ShowArray(DynamicArray* dynamicArray)
{
cout << "array: ";
for (int i = 0; i < dynamicArray->GetLength(); i++)
{
cout << dynamicArray->GetElement(i) << ' ';
}
cout << endl;
}