Take out a piece of paper. We’ll be programming on paper.
public class ArrayList<E> implements List211<E> { /** Holds the items in the list. */ private E[] data; /** The size of the list. */ private int size; /** * Constructs an empty list with an initial capacity of ten. */ public ArrayList() { // your steps / code goes here } /** * Removes the element at the specified position in this list. Shifts any subsequent elements to the * left (subtracts one from their indices). * @param index the index of the element to be removed * @return the element that was removed from the list. * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()) */ public E remove(int index) { // your steps / code goes here. } }
Answer the following questions:
When do you need to resize data?
Why do we keep track of size?