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 intbinarySearch(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:
haystackis notnulland is sorted in increasing order. - Modifies: nothing.
- Effects: if
haystackcontainsneedle, returns the index of the first occurrence ofneedleinhaystack; otherwise, returns-(insertion_point) - 1whereinsertion_pointis the index of the first integer greater thanneedle; note that this implies that the return value is non-negative iffhaystackcontainsneedle.
- Requires:
-