- Iterates through the ArrayList and checks whether the value at the current index is larger than the value at the following index.
- If so, the ArrayList is NOT ordered and will return false.
- If not, it will continue iterating.
- When the index preceding the last index passes this check, this means that the entire ArrayList is sorted and it will return true.
-
String toString()
- Returns string representation of OrderedArrayList in [] format
- Commas separate values
-
int size()
- Accessor method for the instance variable
_sizeof class ArrayList
- Accessor method for the instance variable
-
Integer get(int index)
- Returns the value at index
indexof ArrayList
- Returns the value at index
-
void addLinear(Integer newVal)
- Sets a variable
cto 0 to signal thatnewValhas not been added yet. - Iterates through ArrayList as long as
cis not 1 (i.e.newValhas not been added yet) - If
newValis less than value at index, addnewValat that index and increment c to 1 to signal thatnewValhas been added. - If the addition has still not been performed after the iteration, it means that there are no values in ArrayList and it will add
newValat index 0.
- Sets a variable
-
boolean addBinary(Integer newVal)
- Initializes three variables that indicate the lower, median, and upper indices of subarray of original ArrayList.
- Slices subarray as long as lower end is smaller than or equal to larger end
- Median is updated to reflect the average of the lower and upper indices
- If
newValis smaller than value at median index, set higher end of subarray to be median - 1. - If
newValis equal to value at median index, addnewValat median index and exit method. - Otherwise (i.e. if
newValis greater than value at median index), set lower end of subarray to be median + 1. - If size of ArrayList is 0, that means the upper index during initialization takes the value of -1. This means that the while loop will be ignored and it will immediately add
newValat index 0 and then exit the method.
-
Integer remove(int index)
- Calls ArrayList method
remove()
- Calls ArrayList method