Class ArrayUtils
java.lang.Object
it.unimi.di.prog2.e06.ArrayUtils
Classe di metodi di utilità per array.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static int
binarySearch
(int[] haystack, int needle) Finds the index (or insertion point) of an integer in an array of integers in increasing order.(package private) static void
fill
(int[] array, int value) (package private) static void
insertAt
(int[] array, int insertionPoint, int value) (package private) static void
print
(int[] array)
-
Constructor Details
-
ArrayUtils
private ArrayUtils().
-
-
Method Details
-
binarySearch
static int binarySearch(int[] haystack, int needle) Finds the index (or insertion point) of an integer in an array of integers in increasing order.If the array contains the given integer, returns its index. Otherwise, returns
-(insertion_point) - 1
whereinsertion_point
is the index of the first integer greater thanneedle
; note that this implies that the return value is non-negative iff the array contains the integer.- Parameters:
haystack
- the notnull
array of integers in increasing order.needle
- the integer to look for.- Returns:
- the index of the given integer, or
-insertion_point - 1
if none is present. - See Also:
-
insertAt
static void insertAt(int[] array, int insertionPoint, int value) -
fill
static void fill(int[] array, int value) -
print
static void print(int[] array)
-