-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertion_Array.cpp
More file actions
51 lines (33 loc) · 785 Bytes
/
Insertion_Array.cpp
File metadata and controls
51 lines (33 loc) · 785 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
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std
void insert (int arr[],int n ,int target , int position){
int count =0;
//over-write elements present after this position
for(int i=n+1;count<(n+1)-position;i--){
count++;
arr[i]=arr[i-1];
}
//insert element here
arr[position]=target;
for(int i=0;i<n+1;i++){
cout<<arr[i];
}
};
int main()
int arr [100];
//user entered number of elements
int n ;
cin >>n;
//filled array with given input
for(int i =0;i<n;i++){
cin>>arr[i];
}
//ask number to be iserted
int target;
cin>>target;
//where to be inserted
int position;
cin>>position;
//insert taget at given location
insert(arr,n,target,position);
};