One Dimensional Array Element Insert
tags: array-insert array-copy non-strict-comparison
Insert an element at a given index in an array.
Solution Outline
- Create a temporary array of size one more than the original array.
- Copy the elements at index less than the insert index to the temporary array.
- Skip the value for the insert index, copy the the remaining elements to the temporary array.
- Insert the value at the insert index in the temporary array.
- Change the reference of array to temporary and return it.
|
|