Class BinarySearcher

java.lang.Object
dsa.lab04.solutions.BinarySearcher

public class BinarySearcher extends Object
Binary search.
  • Constructor Details

    • BinarySearcher

      public BinarySearcher()
  • Method Details

    • search

      public <Item extends Comparable<Item>> int search(StaticSequence<Item> items, Item item)
      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 sequence
      item - the searched-for item
      Returns:
      the index of item in items, or -1 if it's not in it
    • search

      public <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.

      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 sequence
      comparator - the comparator
      item - the searched-for item
      Returns:
      the index of item in items, or -1 if it's not in it