ArrayList.java - import java.util ArrayList represents an...

This preview shows page 1 - 2 out of 5 pages.

import java.util.*; /** * ArrayList represents an array implementation of a list. The front of * the list is kept at array index 0. This class will be extended * to create a specific kind of list. * * @author Lewis and Chase * @version 4.0 */ public abstract class ArrayList<T> implements ListADT<T>, Iterable<T> { private final static int DEFAULT_CAPACITY = 100; private final static int NOT_FOUND = -1; protected int rear; protected T[] list; protected int modCount; /** * Creates an empty list using the default capacity. */ public ArrayList() { this(DEFAULT_CAPACITY); } /** * Creates an empty list using the specified capacity. * * @param initialCapacity the integer value of the size of the array list */ public ArrayList(int initialCapacity) { rear = 0; list = (T[])(new Object[initialCapacity]); modCount = 0; } /** * Creates a new array to store the contents of this list with * twice the capacity of the old one. Called by descendant classes * that add elements to the list. */ protected void expandCapacity() { list = Arrays.copyOf(list, list.length*2); } /** * Removes and returns the last element in this list. * * @return the last element in the list * @throws EmptyCollectionException if the element is not in the list */ @Override public T removeLast() throws EmptyCollectionException { //TODO: Implement this. } /** * Removes and returns the first element in this list.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture