Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use c++, thank you Write a function named insertinArray that takes the parameter

ID: 3884030 • Letter: U

Question

Use c++, thank you

Write a function named insertinArray that takes the parameters list as an integer array, size for the capacity of the array, numItems has the number of items in the array, index which is the index where the new item should go, and newVal has the new value to be inserted into the array. If the array is at capacity then the function should return -1, otherwise return 0 for success. int insertInArray(int list[], int size, int* numItems, int index, int newVal) For example, if the array has {9, 2, 8, 3} and the array has the capacity to add a new value, and the new value is '5' at index '2', then the resulting array should be {9, 2, 5, 8, 3} and the function should return 0. You will also need to add one to the numItems variable. Answer: (penalty regime: 0, 5, 10,... %) 1 int insertInArray(int list[], int size, int* numItems, int index, int 2 int timer: 3 if(size==*numItems) 4 return -1: 5 else{ 6 (timer = size: timer > =index + 1: timer--)

Explanation / Answer

Please find my implementation.

Please let me know in case of any issue.

int insertInArray(int list[], int size, int *numItems, int index, int newVal) {

if(numItems == size)

return -1;

// shifting elements from 'index' in right

numItems

for(int i = *numItems; i>index; i--)

list[i] = list[i-1];

// now storing newVal at index

list[index] = newVal;

return 0;

}