(Find the Minimum Value in a vector) Modify your solution to Exercise 6.37 to find the minimum value in a vector instead of an array.
What will be an ideal response?
```
#include
#include
#include
#include
#include
using namespace std;
const int MAXRANGE = 1000;
int recursiveMinimum( const vector< int > &, int, int );
int main()
{
vector< int > array( 10 );
int smallest;
srand( time( 0 ) );
// initialize elements of array to random numbers
for ( size_t loop = 0; loop < array.size(); loop++ )
array[ loop ] = 1 + rand() % MAXRANGE;
// display array
cout << "Array members are:\n";
for ( size_t k = 0; k < array.size(); k++ )
cout << setw( 5 ) << array[ k ];
// find and display smallest array element
cout << '\n';
smallest = recursiveMinimum( array, 0, array.size() - 1 );
cout << "\nSmallest element is: " << smallest << endl;
} // end main
// function to recursively find minimum array element
int recursiveMinimum( const vector< int > &array, int low, int high )
{
static int smallest = MAXRANGE;
// if first element of array is smallest so far
// set smallest equal to that element
if ( array[ low ] < smallest )
smallest = array[ low ];
// if only one element in array, return smallest
// else recursively call recursiveMinimum with new subarray
return low == high ?
smallest : recursiveMinimum( array, low + 1, high );
} // end function recursiveMinimum
```
Array members are:
117 433 783 387 485 157 10 715 287 774
Smallest element is: 10
You might also like to view...
Does the Korn shell support recursive functions?
What will be an ideal response?
It may be helpful to offer ________ to the audience to provide a place for people to take notes
Fill in the blank(s) with correct word
Case B-2Charles has created an illustration consisting mainly of ellipses. The illustration also consists of two identical sets of objects. In order to move and copy the illustration 1 inch to the left of it, what would Charles enter in the Move dialog box?
A. a negative value in the Horizontal text box B. a positive value in the Horizontal text box C. a positive value in the Vertical text box D. a negative value in the Vertical text box
An alternative to the DHCP client daemon, which is obtained from ISC, is the ____________________.
Fill in the blank(s) with the appropriate word(s).