You have been hired to work on software that helps users catalog their board gam
ID: 670882 • Letter: Y
Question
You have been hired to work on software that helps users catalog their board game collections. This software will utilize a binary search when the user selects the search option. You are to write a recursive function to perform the binary search on an array of strings arranged in descending order. The function will return a boolean value. The function should have a string array parameter and a string parameter (representing the item to find) along with parameters for the first and last index of the subsection being searched.
Explanation / Answer
Recursion: Recursion is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem. In computer science a recursive function calls itself directly or indirectly.
template <class elemType>
int orderedArrayListType<elemType>::binarysearch (const elemType& item)
{
int firstele= 0;
int lastele = length -1;
boolean mid;
int list[];
int BinarySearch(,Type & Item, int firstele, int lastele)
bool found = false;
while (firstele <= lastele && !found){
mid = (firstele + lastele) / 2;
if (list[mid] > item)
return BinarySearch(list, item, firstele, mid -1)
found = true;
else if (list[mid] > item)
return BinarySearch( list, item, firstele, mid -1)
lastele = mid - 1;
else
firstele = mid + 1;
}
if (found)
return mid;
else
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.