marcoshuck

Búsqueda por bisección

Sep 13th, 2013
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. int busquedaBi(int *d, int t, int search);
  2.  
  3. int busquedaBi(int *d, int t, int search){
  4.     int izq = 0;
  5.     int der = t - 1;
  6.     int medio;
  7.     int ret = -1;
  8.     while((ret == -1) && (izq <= der))
  9.     {
  10.         medio = (izq + der) / 2;
  11.         if(d[medio] == search)
  12.             ret = medio;
  13.         else if(search < d[medio] )
  14.             der = medio - 1;
  15.         else
  16.             izq = medio + 1;
  17.     }
  18.     return ret;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment