Advertisement
Guest User

Untitled

a guest
May 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //recherche pour voiture
  2. int recherche(struct voiture *v,int nbr,char *critere) //adr, valeur, adr
  3. {
  4. int position=-1,i,ok,g,dr,mil;
  5. g = 0; dr = nbr; ok = 0;
  6. while(ok==0 && g <= dr)
  7. {
  8. mil = (int) ((g+dr)/2);
  9. printf("Avant : [g:%d] [dr:%d] [mil:%d [nbr:%d] [ok:%d]\n",g,dr,mil,nbr,ok);
  10. if(strcmp((v+mil)->nom_voit,critere)==0) {
  11. ok=1; position = mil;
  12. }
  13. else if(strcmp((v+mil)->nom_voit,critere) < 0) {
  14. g = mil + 1;
  15. }
  16. else {
  17. dr = mil - 1;
  18. }
  19. printf("Après : [g:%d] [dr:%d] [mil:%d [nbr:%d] [ok:%d]\n\n",g,dr,mil,nbr,ok);
  20. }
  21. printf("\n Position : %d",position);
  22. return position;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement