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