Write a method reverseCopy that returns a new
ArrayIntList that contains a copy of the values in the original list in
reverse order. For example, if a variable list stores the following
sequence of values:
[17, 42, 3, 8, 9, 12]
and the following call is made:
ArrayIntList list2 = list.reverseCopy();
Then the variable list2 should store the following sequence of values:
[12, 9, 8, 3, 42, 17]
The original list should not be changed by the method. The new list should
have the same capacity as the original. Remember that there is a
constructor for ArrayIntList that takes a capacity as a parameter:
// pre : capacity >= 0
// post: constructs an empty list with the given capacity
public ArrayIntList(int capacity)
If the original list is empty, the result should be an empty list. You are
writing a method for the ArrayIntList class discussed in lecture:
public class ArrayIntList {
private int[] elementData; // list of integers
private int size; // current # of elements in the list
<methods>
}
You may call the ArrayIntList constructor, but otherwise you may not call
any other methods of the ArrayIntList class to solve this problem. You are
not allowed to call methods from the Arrays class like the copyOf method.
Your solution must run in O(n) time where n is the length of the list.