if (results == -1)
cout << "That number does not exist in the array.\n";
else
{
cout << "That ID is found at element " << results;
cout << " in the array\n";
}
return 0;
}
if (results == -1)
cout << "That number does not exist in the array.\n";
else
{
cout << "That ID is found at element " << results;
cout << " in the array\n";
}
return 0;
}
int binarySearch(const int array[], int size, int value)
{
int first = 0,
last = size - 1,
middle,
position = -1,
bool found = false;
while (!found && first + last) /2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle - 1;
else
first = middle + 1;
}
return position;
}