I need Help!
Consider this following modified version of the binary search algorithm. (Modifications are indicated by a comment highlighted asterisks.) With this new version of the binary search algorithmn work correctly for all data? If not, specify a situiation in which this version will fail.
template<class element, class Keytype>
bool binarySearch(const apvector<element> &list, int n, Keytype target, element &object)
{
int low, middle, high;
bool found = false;
low = 0;
high = n;
while ((low <= high) && ! found)
{
middle = (low + high) / 2;
if(list[middle] = target)
found=true;
else if (list[middle] < target)
low = middle; // *** MODIFICATION HERE ***
else
high = middle; // *** MODIFICATION HERE ***
}
if (found)
object=list[middle];
return found;
}