Advertisement
vim_fans

Untitled

Oct 10th, 2021
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.26 KB | None | 0 0
  1. int binsearch(int x, int v[], int n)
  2. {
  3. int low, high, mid;
  4. low = 0;
  5. high = n - 1;
  6. while (low <= high) {
  7. mid = (low+high)/2;
  8. if (x < v[mid])
  9. high = mid + 1;
  10. else if (x > v[mid])
  11. low = mid + 1;
  12. else /* found match */
  13. return mid;
  14. }
  15. return -1; /* no match */
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement