Professional Documents
Culture Documents
DEVOIR
DEVOIR
Exercice D’économie
Abderrahim ouameur
Ticse-info2
Classe dichotomie :
if (tab[mid] == val) {
seTrouve = true;
p = mid;
return;
} else if (tab[mid] < val) {
dichotomie d = new dichotomie(tab, val, mid + 1, dernierelement);
d.start();
try {
d.join();
p = d.Position();
seTrouve = d.isFound();
} catch (Exception e) {}
} else {
dichotomie g = new dichotomie(tab, val, dernierelement, mid - 1);
g.start();
try {
g.join();
p = g.Position();
seTrouve = g.isFound();
} catch (Exception e) {}
}
}
Classe main
public class Main {
public static void main(String[] args) {
int[] tab = {1, 2, 3, 4, 5};
int val = 5;
dichotomie x = new dichotomie(tab, val, 0, tab.length - 1);
x.start();
try {
x.join();
if (x.isFound()) {
System.out.println("5 est dans la position " + x.p);
}
else {
System.out.println(" pas dans le tableau");
}
} catch (Exception e) {;}
}
}