-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_revision.c
56 lines (47 loc) · 1.03 KB
/
array_revision.c
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
#include <stdio.h>
#include <stdlib.h>
void displayArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
{
printf(" %d ", arr[i]);
}
printf("\n");
}
void InsertAtIndex(int arr[], int capacity, int size, int index, int element)
{
if (size >= capacity)
{
printf("array is full");
}
else
{
for (int i = size - 1; i >= index; i--)
{
arr[i + 1] = arr[i];
}
arr[index] = element;
}
}
void deleteAtIndex(int arr[], int size, int index)
{
for (int i = index; i <= size; i++)
{
arr[i] = arr[i + 1];
}
}
int main()
{
int arr[100] = {1, 4, 5, 6, 7, 9};
int element = 8;
int size = 6;
int index = 3;
displayArray(arr, size);
InsertAtIndex(arr, 100, size, index, element);
displayArray(arr, size);
size = size + 1;
displayArray(arr, size);
deleteAtIndex(arr, size, index);
size = size - 1;
displayArray(arr, size);
}