ListTools[BinarySearch] - perform a binary search on a list
|
Calling Sequence
|
|
BinarySearch(L, x, f, g)
|
|
Parameters
|
|
L
|
-
|
list
|
x
|
-
|
anything
|
f
|
-
|
(optional) procedure, operator, algebraic expression, or list
|
g
|
-
|
(optional) procedure, operator, algebraic expression, or list
|
|
|
|
|
Description
|
|
•
|
The BinarySearch(L, x) function performs a binary search on list L for element x. List L is assumed to be sorted. If a match is found, the position of the element is returned; otherwise, the value is returned.
|
|
In this form of the calling sequence, x must be of type numeric or string and the list should have operands of the same type in ascending order.
|
|
If g is not included, boolean equality is used to test if two objects are equal.
|
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
|
|
Download Help Document
Was this information helpful?