Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (22 sloc) 417 Bytes
int search(int array[], int n, int v)
{
int left, right, middle;
left = -1, right = n;
while (left + 1 != right)
{
middle = left + (right - left) / 2;
if (array[middle] < v)
{
left = middle;
}
else
{
right = middle;
}
}
if (right >= n || array[right] != v)
{
right = -1;
}
return right;
}
You can’t perform that action at this time.