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
Explanation / Answer
please rate - thanks #include using namespace std; int binarySearch(int a[],int low,int high,int val); int main() { inti,j,id[10]={5,10,15,20,30,40,50,60,70,80},key=30,max=10,temp; temp= binarySearch(id,0,max,key); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.