C++: Exemple d’utilisation de ‘binary_search’ pour des recherches binaires génériques

Author:

 assert
{filelink=15148}


#include 
#include 
#include 
#include 
using namespace std;

int main()
{
  vector v(5);
  bool found;

  for (int i = 0; i < 7; ++i)
     v[i] = i;

  found = binary_search(v.begin(), v.end(), 3);
  cout << found << " ";

  // Rechercher un élément dans le vecteur
  found = binary_search (v.begin(), v.end(), 9);

  if(found)
  {
	  cout<<"9 existen";
  }
  else
  {
	   cout<<"9 n'existe pas n";
  }
  cout << found;

  return 0;
}

Leave a Reply

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