1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
public class Chercher {
int E[] = { 1, 3, 7, 8, 4, 9, 18, 22, 23, 25, 20, 11, 26, 27, 31, 34, 36, 13 };
int i0, i, X;
int N = E.length;
int d,R ;
public int Chercher (int []E, int V) {
i0 = Math.round(N*V/R) ;
i = i0 ;
X = element(E,i); //(N est la taille de E, R=36 est le nombre de clés possibles)
if(X < V) { d = 1;}
else { d = -1;}
while( i+d != i0 ){ // parcours tout E ***** Ligne de comparaison *****
if(X== V) return X;
i = Math.floorMod(( i + d ), N) ; // parcours tout E
X = element(E,i);
return (Integer) null;
}
return V;
}
public int element(int[] E, int i) {
return E[i];
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
} |
Partager