Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //recherche pour voiture
- int recherche(struct voiture *v,int nbr,char *critere) //adr, valeur, adr
- {
- int position=-1,i,ok,g,dr,mil;
- g = 0; dr = nbr; ok = 0;
- while(ok==0 && g <= dr)
- {
- mil = (int) ((g+dr)/2);
- printf("Avant : [g:%d] [dr:%d] [mil:%d [nbr:%d] [ok:%d]\n",g,dr,mil,nbr,ok);
- if(strcmp((v+mil)->nom_voit,critere)==0) {
- ok=1; position = mil;
- }
- else if(strcmp((v+mil)->nom_voit,critere) < 0) {
- g = mil + 1;
- }
- else {
- dr = mil - 1;
- }
- printf("Après : [g:%d] [dr:%d] [mil:%d [nbr:%d] [ok:%d]\n\n",g,dr,mil,nbr,ok);
- }
- printf("\n Position : %d",position);
- return position;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement