Question: Consider a binary search function. If no match is found, the function returns -1. Modify the function so that it returns a bool value that

Consider a binary search function. If no match is found, the function returns -1. Modify the function so that it returns a bool value that indicates whether a match was found. Add a reference parameter m, which is set to the location of the match if the search was successful. If a was not found, set m to the index of the next larger value instead, or to a.size) if a is larger than all the elements of the vector.

 Consider a binary search function. If no match is found, the

Implement a function bool binary.search (vector & v, int value, int & m) , that uses binary search to find out whether there is an integer value in the vector v of integers. If a match is found, the function returns true, otherwise it returns false. In the above function m is a reference parameter, which must be set to the location of the match if the search was successful. If value were not found, set m to the index of the next larger value instead, or to v.size () if value is larger than all the elements of the vector . Write a program that reads the list of integers from a file data3.txt and displays them on the screen. Then the program must sort the numbers using sort function from C++ library and then display the sorted vector .Finally, implement a loop in which the user is asked to enter a value, which is then searched in the sorted array using the above binary.search function. If value is found display "Found. m-, followed by the value of m. Otherwise display "Not found. m- followed by the value of m. . You can assume that data3.txt contains only integers (no floating point numbers or strings that are not numbers) and that the file has at least one number . Submit the solution as hmw-5-3.cpp . Sample input-output data3.txt - Not. ClWin exe File Edit Format View Help Before sorting 2 3 4543 21-1 fter sorting: 1 1 1 2 2 3 344 5 Enter a value 2 Found. n-4 ontinue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!