Question: How do I do this? Given an array, the index of an element in that array, and a destination location for that element (less than
How do I do this? Given an array, the index of an element in that array, and a destination location for that element (less than or equal to the original index), "insert" that element into its destination, and shift all other elements downward, returning the modified array. Do not create a new array. Simply modify the existing array by moving the necessary elements. insert([4, 7, 2, 8, 5], 3, 0) rightarrow [8, 4, 7, 2, 5] insert([5, 10, 15, 20, 25, 30, 35, 40], 5, 2) rightarrow [5, 10, 30, 15, 20, 25, 35, 40] insert([5, 10, 15, 20, 25, 30, 35, 40], 5, 5) rightarrow [5, 10, 15, 20, 25, 30, 35, 40]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
