Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int trouverIndice(int unEntier){
- //recherche sequentielle
- for (int i = 0; i < this.nombreDEntiers; i++) {
- if(this.tableDEntiers[i]==unEntier)
- return i;
- if(this.tableDEntiers[i]>unEntier)
- return -1;
- }
- return -1;
- }
- /* fonction de recherche dichotomique qui renvoie un indice où se trouve la valeur "val" si elle est dans le tableau "tab[]" et -1 si cette valeur n'y est pas */
- private int rechercheDicho(int tab[], int nbVal, int val){
- boolean trouve;
- int id;
- int ifin;
- int im;
- trouve = false;
- id = 0;
- ifin = nbVal;
- /* boucle de recherche */
- while(!trouve && ((ifin - id) > 1)){
- im = (id + ifin)/2;
- trouve = (tab[im] == val);
- if(tab[im] > val) ifin = im;
- }
- /* test conditionnant la valeur que la fonction va renvoyer */
- if(tab[id] == val) return(id);
- else return(-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement