write in c++ pls Write a function named insertinArray that takes the following p
ID: 3743917 • Letter: W
Question
write in c++ pls
Write a function named insertinArray that takes the following parameters: listlnput: a char array capacity: capacity of the array numitems: number of items currently in the array index: index at which to insert the new item newVal: value to insert into the array If the array is at capacity then the function should return-1. Otherwise, insert newWal at index and return 0 for success int insertInArray(char listInput 1, int capacity, int numItems, int index, char newWal) For example, if the array is {gr.2·B', '3') and it has the capacity to add a new value of 5 at index 2, then the resulting array should be {'9·'2·'5·B','3') and the function should return 0. The numitems variable will increment from 4 to 5. Answer: (penalty regime: 05.10 %) 1 int insertInArray (char list InputI 1, int capacity, int numItems, int index, char newWal)Explanation / Answer
int insertInArray(char listInput[], int capacity, int *numItems, int index, char newVal) { if(*numItems index; --i) { listInput[i] = listInput[i-1]; } listInput[index] = newVal; size++; *numItems = size; return 0; } else { return -1; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.