Write a new method for the ArrayIntList
class named remove
that accepts an integer index as its parameter and removes the value at the given index, shifting subsequent values to the left.
For example, if an ArrayIntList
variable named list
stores the following values:
[3, 19, 42, 7, -3, 4]
The call of list.remove(1);
should modify the list to store the following sequence of integers:
[3, 42, 7, -3, 4]
You should throw an ArrayIndexOutOfBoundsException
if the index is out of range; that is, if it is not between 0 and the list's size - 1, inclusive.
Assume you are adding to the ArrayIntList
class with following members:
public class ArrayIntList {
private int[] elementData;
private int size;
// construct a new empty list of capacity 10
public ArrayIntList() { ... }
// add to end of list
public void add(int value) { ... }
// throw ArrayIndexOutOfBoundsException if index not between min/max inclusive
private void checkIndex(int index, int min, int max) { ... }
// ensure that elementData.length >= capacity
private void ensureCapacity(int capacity) { ... }
...
// your code goes here
}