std algorithm binary search code example
Example: c++ binary search
int result = -1;
int low = 0;
int high = N-1; // N - # of elements
while (low <= high)
{ mid = (low + high) / 2;
if ( item == vector[mid])
{ result = mid;
break;
}
else if (item > vector[mid] )
{ low = mid + 1; }
else { high = mid - 1; }
}