For this lab, you will implement the recursive binary search algorithm's pseudocode. Use lab7.cpp for your main function. This sets up a sorted array and passes it into the binary search function. You can alter the values in the array, but make sure to keep them sorted.
The pseudocode for binary search is:
Given: sorted array, key to search for, start index, end index
Returns: index where key is found or -1 if key is not in array
if start or end indices are invalid
return -1
end-if
if start is equal to end
if array[start] is equal to key
return start
else
return -1
end-if
end-if
calculate mid = (start + end) / 2
if array[mid] is equal to key
return mid
else if array[mid] is less-than key (search right)
return binarySearch(array, key, mid+1, end)
else (key is less-than array[mid], search left)
return binarySearch(array, key, start, mid-1)
end-if
Email your completed lab7.cpp to Terry.