Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. int binarysearch(int a, int mass[], int n)
  2. {
  3.     int low, high, middle;
  4.     low = 0;
  5.     high = n - 1;
  6.     while (low <= high)
  7.     {
  8.         middle = (low + high) / 2;
  9.         if (a < mass[middle])
  10.             high = middle - 1;
  11.         else if (a > mass[middle])
  12.             low = middle + 1;
  13.         else
  14.             return middle;
  15.     }
  16.     return -1;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement