++


binary_search()


template < class ForwardIterator, class Type >

bool

binary_search( ForwardIterator first,

ForwardIterator last, const Type &value );

template < class ForwardIterator, class Type >

bool

binary_search( ForwardIterator first,

ForwardIterator last, const Type &value,

Compare comp );

binary_search() value , [first,last). , true,   false. , . -.

#include <algorithm>

#include <vector>

#include <assert.h>

 

int main()

{

int ia[] = {29,23,20,22,17,15,26,51,19,12,35,40};

vector< int, allocator > vec( ia, ia+12 );

 

sort( &ia[0], &ia[12] );

bool found_it = binary_search( &ia[0], &ia[12], 18 );

assert( found_it == false );

 

vector< int > vec( ia, ia+12 );

sort( vec.begin(), vec.end(), greater<int>() );

found_it = binary_search( vec.begin(), vec.end(),

26, greater<int>() );

assert( found_it == true );

}




- -  - -  - -