Trouver la dernière position d’insertion d’élément dans la collection

Author:


{filelink=15157}


#include 
using std::cout;
using std::endl;

#include 
#include 
#include 

int main()
{
   int tab[ 10 ] = { 1, 2, 3, 4, 4, 6, 6, 6, 6, 8 };
   std::vector< int > v( tab, tab + 10 );
   std::ostream_iterator< int > output( cout, " " );

   std::copy( v.begin(), v.end(), output );

   std::vector< int >::iterator ub;
   ub = std::upper_bound( v.begin(), v.end(), 6 );
   cout <<"La dernière position d'insertion de 6 est entre"
	    << *( ub - 1 ) <<" et "
		<<*ub <
    

Leave a Reply

Your email address will not be published. Required fields are marked *