Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int bsearch(int[] a, int x) {
- int low = 0;
- int high = a.length - 1;
- int mid;
- if (a[0] < x) {
- return 0;
- }
- while (low <= high) {
- mid = (low + high) / 2;
- if (a[mid] > x)
- low = mid + 1;
- else if (a[mid] < x)
- high = mid - 1;
- else
- return mid + 1;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement