Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions