Implement the recursive version of the binary search algorithm inC++. Write the
ID: 3617017 • Letter: I
Question
Implement the recursive version of the binary search algorithm inC++. Write the code to test it out on a sample input.template<class elemType>
int orderedArrayListType<elemType>::binarySearch(constelemType& item)
{
int first = 0;
int last = length - 1;
int mid;
bool found = false;
while(first <= last && !found)
{
mid = (first + last) / 2;
if(list[mid] == item)
found =true;
else
if(list[mid]> item)
last = mid- 1;
else
first =mid + 1;
}
if(found)
return mid;
else
return -1;
}//end binarySearch