Package dsa

Class LinearSearch

java.lang.Object
dsa.LinearSearch

public class LinearSearch extends Object
This library implements linear search.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    indexOf(double[] a, double item)
    Returns the index of item in the array a, or -1.
    static int
    indexOf(int[] a, int item)
    Returns the index of item in the array a, or -1.
    static int
    indexOf(Object[] a, Object item)
    Returns the index of item in the array a, or -1.
    static <T> int
    indexOf(T[] a, T item, Comparator<T> c)
    Returns the index of item in the array a, or -1 (comparisons are made using the comparator c).
    static void
    main(String[] args)
    Unit tests the library.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • indexOf

      public static int indexOf(Object[] a, Object item)
      Returns the index of item in the array a, or -1.
      Parameters:
      a - array of objects.
      item - search item.
      Returns:
      the index of item in the array a, or -1.
    • indexOf

      public static <T> int indexOf(T[] a, T item, Comparator<T> c)
      Returns the index of item in the array a, or -1 (comparisons are made using the comparator c).
      Type Parameters:
      T - the type of items in a.
      Parameters:
      a - sorted array of comparable objects.
      item - search item.
      c - the comparator.
      Returns:
      the index of item in the sorted array a, or -1.
    • indexOf

      public static int indexOf(int[] a, int item)
      Returns the index of item in the array a, or -1.
      Parameters:
      a - array of objects.
      item - search item.
      Returns:
      the index of item in the array a, or -1.
    • indexOf

      public static int indexOf(double[] a, double item)
      Returns the index of item in the array a, or -1.
      Parameters:
      a - array of objects.
      item - search item.
      Returns:
      the index of item in the array a, or -1.
    • main

      public static void main(String[] args)
      Unit tests the library.
      Parameters:
      args - the command-line arguments.