int binarySearch(const int list[], int listLength,
int searchItem)
{
int first = 0;
int last = listLength - 1;
int mid; ➊
bool found = false;
while (first <= last && !found) ➋
{
mid = (first + last) / 2; ➌
if (list[mid] == searchItem) ➍
found = true;
else
if (list[mid] > searchItem) ➎
last = mid - 1;
else
first = mid + 1;
}
if (found)
return mid;
else
return -1;
}