6 minutes,
3 points
1. Look at the
following implementation of SimpleArrayList :
public class SimpleArrayList implements List {
// instance variables
private Object[ ] elements; // elements stored in
elements[0..numElems-1]
private int numElems; // size: # of elements currently
in the list
/** Construct new list with
specified capacity */
public SimpleArrayList(int
capacity) {
elements = new Object[capacity];
numElems = 0;
}
/** Returns first location of
object obj in this list if found, otherwise return –1 */
public int indexOf(Object obj)
{
}
}
Finish the implementation of the method indexOf, which returns the index of the array where the object is first found (starting from the initial index of the array). Otherwise, if the object is not found in the list, return -1. You may not use any other methods of SimpleArrayList or List in your implementation.