// Helene Martin, CSE 143 // An ArrayIntList stores an ordered list of integers. 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; // optional; size is initialized to 0 by default } // 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) { elementData[size] = value; size++; } // 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++; } // Returns the value at the given index. // For now we will assume that 0 <= index < size. public int get(int index) { return elementData[index]; } // Sets the given index to store the given value. // For now we will assume that 0 <= index < size. public void set(int index, int value) { elementData[index] = value; } // Returns a String representation of the list consisting of the elements // in order, separated by commas and enclosed in square brackets. public String toString() { String result = "["; if (size > 0) { result += elementData[0]; for (int i = 1; i < size; i++) { result += ", " + elementData[i]; } } result += "]"; return result; } }