File: binarysearch.yo

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (35 lines) | stat: -rw-r--r-- 1,710 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    hi(binary_search)
    itemization(
        it() Header file: tt(<algorithm>)
        it() Function prototypes:
        itemization(
            itt(bool binary_search(ForwardIterator first, ForwardIterator
last, Type const &value);)
            itt(bool binary_search(ForwardIterator first, ForwardIterator
last, Type const &value, Comparator comp);)
        )
        it() Description:
        itemization(
            it() The first prototype: tt(value) is looked up using binary
search in the series of elements implied by the iterator range rangett(first,
last). The elements in the range must have been sorted by the
tt(Type::operator<) function. tt(True) is returned if the element was found,
tt(false) otherwise.
            it() The second prototype: tt(value) is looked up using binary
search in the series of elements implied by the iterator range rangett(first,
last). The elements in the range must have been sorted by the tt(Comparator)
function object. tt(True) is returned if the element was found, tt(false)
otherwise. As illustrated by the following example, the function object
function's first parameter refers to an element in the iterator range, while
the function object's second parameter refers to tt(value).
        )
        it() Example:
        verbinclude(-a examples/binarysearch.cc)
    )

If tt(value) is in fact present in the range of values, then this generic
algorithm doesn't answer the question where tt(value) is located. If that
question must be answered the generic algorithms link(lower_bound)(LOWERBOUND)
and link(upper_bound)(UPPERBOUND) can be used. Refer to section
ref(UPPERBOUND) for an extensive example illustrating the use of these latter
two algorithms.