++


lower_bound()


template< class ForwardIterator, class Type >

ForwardIterator

lower_bound( ForwardIterator first,

ForwardIterator last, const Type &value );

 

 

template< class ForwardIterator, class Type, class Compare >

ForwardIterator

lower_bound( ForwardIterator first,

ForwardIterator last, const Type &value,

class Compare );

lower_bound() , , [first,last), value, . , value. , :

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

lower_bound() value=21 , 23. 22 . , , comp.

#include <algorithm>

#include <vector>

#include <iostream.h>

int main()

{

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

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

 

int search_value = 18;

int *ptr = lower_bound( ia, ia+12, search_value );

 

// :

// , 18, - 19

// 17

cout << " , "

<< search_value

<< ", "

<< *ptr << endl

<< " "

<< *(ptr-1) << endl;

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

 

// ...




- -  - -  - -