Shift Left to Remove at an Index
easyQuestion 557Removing from the middle of an array leaves a gap, and a dynamic array closes it by moving every later value one slot to the left. This time the shift starts at the gap and works toward the back. size is the number of slots in use (the array data may be longer), so the loop must stop at the last value in use.
Requirements:
1. removeAt(int index) returns the value that was at index. The bounds check and the line that saves that value are already written.
2. Move every value after index one slot to the left, then lower size by one.
3. An index that is negative or not less than size returns -1 and changes nothing.
Do NOT write a main method.
Expected output
20 [10, 30, 40] 10 [30, 40] 40 [30] 1
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Data Structures & AlgorithmsDynamic Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.