Class BinarySearch
Sorter
|
+--BinarySearch
- public class BinarySearch
- extends Sorter
Class for performing "instrumented" binary search.
(See source code at
BinarySearch.java.)
| Method Summary |
static void | main(String[] args) Performs simple tests. |
static SearchResult | search(Comparable[] a, Comparable x) Searches an array for an element. |
static SearchResult | search(Object[] a, Object x, Comparator c) Searches an array for an element. |
static void | testSearch(String testName, Object[] a, Object x, Comparator c) Tests search:
Performs search, prints result, and prints values of counter, preceded
by header message. |
main
public static void main(String[] args)
- Performs simple tests.
- Parameters:
- args command-line arguments -- data to search, or none to
use default data
search
public static SearchResult search(Comparable[] a, Comparable x)
- Searches an array for an element.
- Parameters:
- a array to search (assumed to be sorted)
- x element to search for
- Returns: object containing count of comparison plus search result
(true if x is an element of a, false otherwise)
search
public static SearchResult search(Object[] a, Object x, Comparator c)
- Searches an array for an element.
- Parameters:
- a array to search (assumed to be sorted)
- x element to search for
- c comparator containing compare method to use, or null to use
objects' compareTo method (in which case a and x should be Comparable)
- Returns: object containing count of comparison plus search result
(true if x is an element of a, false otherwise)
testSearch
public static void testSearch(String testName, Object[] a, Object x, Comparator c)
- Tests search:
Performs search, prints result, and prints values of counter, preceded
by header message.
- Parameters:
- testName "test name" for header message
- a array to search
- x element to search for
- c comparator, or null to use compareTo