Advertisement
franciscominajas

Binario

Sep 12th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. int busqueda (int arreglo[], int n, int dato)
  2. {
  3.     int medio, info=0, arriba=n-1;
  4.    
  5.     while(info<=arriba)
  6.     {
  7.         medio=(info+arriba)/2;
  8.         if(arreglo[medio]==dato)
  9.         {
  10.             return medio;
  11.         }
  12.         else if(dato<arreglo[medio])
  13.         {
  14.             arriba=medio-1;
  15.         }
  16.         else
  17.         {
  18.             info=medio+1;
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement