Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Modify the SearchableVector class template presented in this chapter so that it per- forms a binary search instead of a linear search. Test the template

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

#ifndef SEARCHABLEVECTOR_H #define SEARCHABLEVECTOR_H #include "SimpleVector.h" template class SearchableVector : public SimpleVector { public: // Default constructor SearchableVector() : SimpleVector() { } // Constructor SearchableVector(int size) : SimpleVector(size) { } // Copy constructor SearchableVector(const SearchableVector &); // Accessor to find an item int findItem(const T); }; //******************************************************* // Copy constructor * //******************************************************* template SearchableVector::SearchableVector(const SearchableVector &obj) : SimpleVector(obj.size()) { for(int count = 0; count < this->size(); count++) this->operator[](count) = obj[count]; } //******************************************************** // findItem function * // This function searches for item. If item is found * // the subscript is returned. Otherwise 1 is returned. * //******************************************************** template int SearchableVector::findItem(const T item) { for (int count = 0; count <= this->size(); count++)16.4 Class Templates 1003 { if (getElementAt(count) == item) return count; } return 1; } #endif

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students explore these related Databases questions

Question

Distinguish between hearing and listening.

Answered: 3 weeks ago

Question

Use your voice effectively.

Answered: 3 weeks ago