Question: Write a program that has at least 20 integers stored in an array in ascending order. It should call a function that uses the linear

Write a program that has at least 20 integers stored in an array in ascending order. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these two counts on the screen.

This is the middle of the code. There are at least 10 lines above this portion and 13 lines below it.

// Compare searches for a value in the middle of the array cout << "Searching for a value in the middle of the array -- "; cout << "Searching for the value 296. "; numCompares = linearSearchBench(tests, SIZE, 296); cout << "The linear search made " << numCompares << " comparisons. "; numCompares = binarySearchBench(tests, SIZE, 296); cout << "The binary search made " << numCompares << " comparisons. "; // Compare searches for a value at the end of the array cout << " Searching for a value at the end of the array -- "; cout << "Searching for the value 600. "; numCompares = linearSearchBench(tests, SIZE, 600); cout << "The linear search made " << numCompares << " comparisons. "; numCompares = binarySearchBench(tests, SIZE, 600); cout << "The binary search made " << numCompares << " comparisons. "; // Compare searches for a value not in the array cout << " Searching for a value not in the array -- "; cout << "Searching for the value 312. "; numCompares = linearSearchBench(tests, SIZE, 312); cout << "The linear search made " << numCompares << " comparisons. "; numCompares = binarySearchBench(tests, SIZE, 312); cout << "The binary search made " << numCompares << " comparisons. "; return 0; }

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!