// CSE 143, Winter 2012 // An ArrayIntList object stores an ordered 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[] elements; private int size; // Initializes a new empty list with initial capacity of 10 integers. public ArrayIntList() { elements = 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) { elements[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) { // shifting over elements to make room for the new value for (int i = size; i > index; i--) { elements[i] = elements[i - 1]; } elements[index] = value; 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 elements[index]; } // Returns true if the list does not contain any elements. public boolean isEmpty() { return size == 0; } // 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 - 2; i++) { elements[i] = elements[i + 1]; } elements[size - 1] = 0; size--; } // 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) { elements[index] = value; } // Returns the number of elements in the list. public int size() { return size; } }