Package dsa.lab04.solutions
Class BinarySearcher
java.lang.Object
dsa.lab04.solutions.BinarySearcher
Binary search.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<Item extends Comparable<Item>>
intsearch
(StaticSequence<Item> items, Item item) Finds the index of the given item in the given sequence using binary search.<Item> int
search
(StaticSequence<Item> items, Comparator<Item> comparator, Item item) Finds the index of the given item in the given sequence using binary search.
-
Constructor Details
-
BinarySearcher
public BinarySearcher()
-
-
Method Details
-
search
Finds the index of the given item in the given sequence using binary search.If the item isn't contained in the sequence, returns -1.
The sequence must be sorted for the search to work properly.
- Type Parameters:
Item
- the item type- Parameters:
items
- the sorted sequenceitem
- the searched-for item- Returns:
- the index of
item
initems
, or -1 if it's not in it
-
search
Finds the index of the given item in the given sequence using binary search.If the item isn't contained in the sequence, returns -1.
The sequence must be sorted for the search to work properly.
- Type Parameters:
Item
- the item type- Parameters:
items
- the sorted sequencecomparator
- the comparatoritem
- the searched-for item- Returns:
- the index of
item
initems
, or -1 if it's not in it
-