// CSE 143, Summer 2012 // An ArrayIntList object stores a list of integers using // an unfilled array. // This is an unfinished "in-progress" version of the class. // We will work on it more the rest of this week. public class ArrayIntList { private int[] elementData; private int size; // Initializes a new empty list with initial capacity of 10 integers. public ArrayIntList() { elementData = new int[10]; size = 0; } // Adds the given value to the end of the list. // For now we will assume that the array has room to fit the new element. public void add(int value) { add (size, value); } // Inserts the given value into the list at the given index. // For now we will assume that 0 <= index <= size. // For now we will assume that the array has room to fit the new element. public void add (int index, int value) { for (int i = size; i > index; i--) { elementData[i] = elementData[i-1]; } elementData[index] = value; size++; } // Removes the value from the given index, shifting following elements left // by 1 slot to cover the hole. // For now we will assume that 0 <= index < size. public void remove(int index) { for (int i = index; i < size; i++) { elementData[i] = elementData[i+1]; } elementData[size] = 0; size--; } // Returns the number of elements in the list. public int size() { return size; } // Returns the value in the list at the given index. // For now we will assume that 0 <= index < size. public int get(int index) { return elementData[index]; } }