Question: In C++ SearchableVector Modification Modify the SearchableVector class template presented in this chapter so that it performs a binary search instead of a linear search.

In C++

SearchableVector Modification

Modify the SearchableVector class template presented in this chapter so that it performs a binary search instead of a linear search. Test the template in a driver program.

REPORTING FORMAT: Source Code & Testing Results

#include
#include "searchvect.h"
using namespace std;
int main()
{
const int SIZE = 10;
SearchableVector intTable(SIZE);
SearchableVector doubleTable(SIZE);
// Store values in the vectors.
for (int x = 0; x < SIZE; x++)
{
intTable[x] = (x * 2);
doubleTable[x] = (x * 2.14);
}
// Display the values in the vectors.
cout << "These values are in intTable: ";
for (int x = 0; x < SIZE; x++)
cout << intTable[x] << " ";
cout << endl;
cout << "These values are in doubleTable: ";
for (int x = 0; x < SIZE; x++)
cout << doubleTable[x] << " ";
cout << endl;
// Now search for values in the vectors.
int result;
cout << "Searching for 6 in intTable. ";
result = intTable.findItem(6);
if (result == -1)
cout << "6 was not found in intTable. ";
else
cout << "6 was found at subscript "
<< result << endl;
cout << "Searching for 12.84 in doubleTable. ";
result = doubleTable.findItem(12.84);
if (result == -1)
cout << "12.84 was not found in doubleTable. ";
else
cout << "12.84 was found at subscript "
<< result << endl;
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!