-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert.cpp
46 lines (40 loc) · 896 Bytes
/
insert.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
#include <bits/stdc++.h>
using namespace std;
void insert(int index, int value, int arr[])
{
int len = sizeof(arr) / sizeof(arr[0]);
int j = len;
while (j > index)
{
arr[j] = arr[j - 1];
j--;
}
arr[index] = value;
for (int i = 0; i <= len; i++)
{
cout << arr[i] << endl;
}
}
void deleteArr(int index, int arr[]){
int i = 0;
cout << "size" <<sizeof(arr) / 2 <<endl;
while (i < sizeof(arr) / 2){
if(i >= index){
arr[i] = arr[i+1];
}
i++;
}
for (int j = 0; j < sizeof(arr) / 2; j++)
{
cout <<"Element on index " << j+1 << " : " << arr[j] << endl;
}
}
int main()
{
int numbers[] = {45, 56, 30,48};
int main[] = {45,3,5,56};
insert(2, 4, main);
cout << "========================" <<endl;
deleteArr(3, numbers);
return 0;
}