-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeletion.cpp
More file actions
49 lines (47 loc) · 1.01 KB
/
Deletion.cpp
File metadata and controls
49 lines (47 loc) · 1.01 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
#include <bits/stdc++.h>
using namespace std;
#define arr_size 100
//O(n) TimeComplexity
void deletion(int array[], int index, int &elements)
{
if (index < 0 || index > elements)
{
return;
}
else
{
array[index] = -1;
for (int i = index; i < elements; ++i)
{
array[i] = array[i + 1];
}
--elements;
}
}
int main()
{
int array[arr_size];
for (int i = 0; i < arr_size; ++i)
{
array[i] = -1;
}
int elements = 9;
int s_array[elements] = {1, 4, 3, 8, 9, 10, 21, 20, 16, 13};
cout << "Array before deletion of element:";
for (int i = 0; i < elements + 1; ++i)
{
array[i] = s_array[i];
cout << array[i] << " ";
}
cout << endl;
int index;
cin >> index;
deletion(array, index, elements);
cout << endl;
cout << "Array after deletion of element at index " << index << ":";
for (int i = 0; i < elements + 1; ++i)
{
cout << array[i] << " ";
}
return 0;
}