Advertisement
pellekrogholt

Untitled

May 7th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.24 KB | None | 0 0
  1.  int lo = 0;
  2.  int hi = a.length - 1;
  3.  while (lo <= hi) {
  4.     // Key is in a[lo..hi] or not present.
  5.     int mid = lo + (hi - lo) / 2;
  6.     if      (key < a[mid]) hi = mid - 1;
  7.     else if (key > a[mid]) lo = mid + 1;
  8.     else return mid;
  9.  }
  10.  return -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement