I'm in a C++ intro class taking an exam. Please answer ASAP!
Fill-In-The-Blank for the Binary Search
int binary(vector<int> V, int key)
{
int first, last, mid;
bool found = false;
first = 0;
last = V.size() - 1;
while (first <= last && !found)
{
mid = (first + last) / 2;
if (V[mid] == key)
{
found = true;
}
else if (V[mid] < key)
{
first = mid + 1;
}
else
{
last = mid - 1;
}
}
if (found)
{
return mid;
}
else
{
return -1;
}
}