(Recursive Linear Search) Modify Exercise 7.33 to use recursive function recursiveLin- earSearch to perform a linear search of the vector. The function should receive the search key and starting index as arguments. If the search key is found, return its index in the vector; otherwise, re- turn –1. Each call to the recursive function should check one element value in the vector.
What will be an ideal response?
```
// Searching a vector with recursive linear search.
#include
#include
using namespace std;
int recursiveLinearSearch( vector < int > &, int, int, int );
int main()
{
const int SIZE = 100;
vector < int > data( SIZE );
int searchKey;
int element;
// initialize vector elements
for ( int loop = 0; loop < SIZE; loop++ )
data[ loop ] = 2 * loop;
// obtain search key from user
cout << "Enter the integer search key: ";
cin >> searchKey;
// search array for search key
element = recursiveLinearSearch( data, searchKey, 0, SIZE - 1 );
// display if search key was found
if ( element != -1 )
cout << "Found value in element " << element << endl;
else
cout << "Value not found" << endl;
return 0; // indicates successful termination
} // end main
// function to search vector for specified key
int recursiveLinearSearch(
vector < int > &array, int key, int low, int high )
{
// search array for key
if ( array[ low ] == key )
return low;
else if ( low == high )
return -1;
else
return recursiveLinearSearch( array, key, low + 1, high );
} // end function recursiveLinearSearch
```
Enter the integer search key: 14
Found value in element 7
Enter the integer search key: 15
Value not found
You might also like to view...
in a class called Employee that has explicitly defined constructors, you can specify that the default constructor should be generated with the declaration ________.
a. Employee() = decltype; b. Employee() = explicit; c. Employee() = default; d. Employee() = generate:
________ are displayed as dotted horizontal and vertical lines and indicate the pointer's position
A) Headers B) Rotation handles C) Ruler guides D) Sizing handles
Which ordered pair is a solution of the system of equations?
A.
B.
_______ management is concerned with specifically keeping track of the configuration of each system in use and the changes made to each.
Fill in the blank(s) with the appropriate word(s).