-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_insertion_of_array.c
More file actions
43 lines (37 loc) · 969 Bytes
/
Copy path10_insertion_of_array.c
File metadata and controls
43 lines (37 loc) · 969 Bytes
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
#include<stdio.h>
#include<stdlib.h>
void display(int arr[], int n){
//Code for Traversal
for (int i = 0; i < n; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
int indInsert(int arr[], int size, int element, int capacity, int index){
//Code for Insertion
if(size>=capacity){
return -1;
}
for(int i = size-1; i>=index; i--){
arr[i+1] = arr[i];
}
arr[index] = element;
return 1;
}
int main(){
int arr[100] = {34,45,54,12,67,12,45};
int size = 7, element = 23, index = 6;
display(arr, size);
indInsert(arr, size, element, 100, index);
size+=1;
display(arr, size);
// int result = indInsert(arr, size, element, 100, index);
// size+=1;
// //Check whether insertion is successful or not.
// if(result==1){
// printf("Insertion successful\n");
// display(arr, size);
// }
// else printf("Insertion failed!!!\n");
return 0;
}