Class ArrayUtils
java.lang.Object
it.unimi.di.prog2.s05.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.
-
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.- Requires:
haystack
is notnull
and is sorted in increasing order. - Modifies: nothing.
- Effects: if
haystack
containsneedle
, returns the index of the first occurrence ofneedle
inhaystack
; 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 iffhaystack
containsneedle
.
- Requires:
-