|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectBinarySearcher
public class BinarySearcher
The BinarySearcher Java application runs a small test on the
search method from Chapter 11 (using a binary search to
find a specified number in an array).
| Constructor Summary | |
|---|---|
BinarySearcher()
|
|
| Method Summary | |
|---|---|
static void |
main(java.lang.String[] args)
The main method prints a table of test results, searching for numbers in an array that contains 2, 4, 6, 8, 10, 12, and 14. |
static int |
search(int[] a,
int first,
int size,
int target)
Search part of a sorted array for a specified target. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BinarySearcher()
| Method Detail |
|---|
public static void main(java.lang.String[] args)
String arguments (args) are not used
in this implementation.
public static int search(int[] a,
int first,
int size,
int target)
a - the array to searchfirst - the first index of the part of the array to searchsize - the number of elements to search, starting at
a[first]target - the element to search for
size > 0, then first through
first+size-1 must be valid indexes for the array a.
Also, starting at a[first], the next size
elements are sorted in increasing order from small to large.
target appears in the array segment starting at
a[first] and containing size elements,
then the return value is the index of a location that
contains target; otherwise the return value is -1.
ArrayIndexOutOfBounds - Exception
Indicates that some index in the range first
through first+size-1 is outside the range of
valid indexes for the array a.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||