Constructor and Description |
---|
IntList()
This is the default constructor that creates an
IntList with
initial length 10. |
IntList(int size)
This is the default constructor that creates an
IntList with
initial length size . |
Modifier and Type | Method and Description |
---|---|
void |
add(int val)
Adds the element
val at the end of the list. |
int |
addConditional(int val)
Adds
val to the list only if
it is not already contained in the list. |
void |
addToValues(int start,
int end,
int offset)
Adds a constant to all internal values between start and end
|
int |
binarySearch(int key,
int fromIndex,
int toIndex)
Performs a binary search for element
key by calling
Arrays.binarySearch(int[], int, int, int) on the internal array. |
void |
clear()
Removes all elements from the list.
|
IntList |
clone() |
int |
contains(int val)
Checks if
val is already returned in the list. |
boolean |
equals(Object o) |
int |
get(int index)
Returns the element with the specified
index . |
int |
interpolationSearch(int key,
int fromIndex,
int toIndex)
Performs an interpolation search for element
key on the internal array. |
int |
length()
Returns the number of inserted elements.
|
int |
pop()
Returns the last element and removes it from the list.
|
void |
reverse()
This method reverses the list, i.e., after invoking this method the formerly
first element is than the last, the formerly second element is than the last but one, ...
|
void |
sort()
This method sorts the elements of the list.
|
int[] |
toArray()
This method returns an
int array containing all elements of
the list. |
String |
toString() |
public IntList()
IntList
with
initial length 10.public IntList(int size) throws IllegalArgumentException
IntList
with
initial length size
.size
- the initial size, has to be positiveIllegalArgumentException
- if size
is less than 1public IntList clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public void add(int val)
val
at the end of the list.val
- the element that should be insertedpublic void addToValues(int start, int end, int offset)
start
- the first indexend
- the last index (exclusive)offset
- the constant to be addedpublic int addConditional(int val)
val
to the list only if
it is not already contained in the list.val
- the value to be addedval
if it is already contained in the list and -1 otherwisepublic void clear()
public int get(int index)
index
.index
- the specified index of the element to returnpublic int pop()
public int contains(int val)
val
is already returned in the list.val
- the valueval
if it is contained in the list and -1 otherwisepublic int length()
public int[] toArray()
int
array containing all elements of
the list.int
array containing all elements of the listpublic void reverse()
public void sort()
Arrays.sort(int[], int, int)
public int binarySearch(int key, int fromIndex, int toIndex)
key
by calling
Arrays.binarySearch(int[], int, int, int)
on the internal array.key
- the key to search forfromIndex
- the first element consideredtoIndex
- the first element not consideredArrays.binarySearch(int[], int, int, int)
public int interpolationSearch(int key, int fromIndex, int toIndex)
key
on the internal array.key
- the key to search forfromIndex
- the first element consideredtoIndex
- the first element not consideredArrays.binarySearch(int[], int, int, int)