#include #include using namespace std; // pour IFT 1166 pas pour IFT 1810 : version récursive de la recherche dichotomique int indDicho(int aChercher, int mini, int maxi, int t[]) { if (mini > maxi) return -1 ; else { int milieu = (mini + maxi) / 2 ; if ( aChercher < t[milieu]) return indDicho(aChercher, mini, milieu-1, t); else if (aChercher > t[milieu]) return indDicho(aChercher, milieu+1, maxi, t); else return milieu; } } int main() { int numero[] = { 25 , 47, 52, 58, 75, 80, 86, 100 }, nbEmp = sizeof(numero) / sizeof(int); cout << "Recherche de 52 : " << indDicho(52, 0, nbEmp-1, numero) << endl ; cout << "Recherche de 80 : " << indDicho(80, 0, nbEmp-1, numero) << endl ; cout << "Recherche de 95 : " << indDicho(95, 0, nbEmp-1, numero) << endl ; return 0; } /* Exécution : Recherche de 52 : 2 Recherche de 80 : 5 Recherche de 95 : -1 -------------------------------- Process exited after 0.02357 seconds with return value 0 Appuyez sur une touche pour continuer... */