Model an algorithm in pseudocode, a flowchart, or a UML activity diagram to repr
ID: 3625841 • Letter: M
Question
Model an algorithm in pseudocode, a flowchart, or a UML activity diagram to represent the program prior to coding.Write a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the element with the smallest value in the array. The function should stop processing and return control to its caller if it receives a one-element array.
Hints:
Write a program to test your function. Populate an array with randomly generated integers.
•&?ßsp;Function recursiveMinimum should take as its arguments the array, a low value and a high value. The low and high values represent the boundaries of the array, respectively.
•&?ßsp;Recursive functions involving arrays approach their base case by reducing the size of the array using boundaries, not by literally passing a smaller array. Your function should approach the base case in the following manner: low+++ until low == high.
Explanation / Answer
#include<iostream>
using std::cout;
using std::cin;
int recursiveMinimum( const int [], int, int);
int main()
{
const int size = 10;
int myArray[size];
int startSubScript = 0;
for (int i = 0; i < size; i++)
{
cout << "Enter the " << i+1 << " element : ";
cin >> myArray[i];
}
cout << "The minimum value in the array is " << recursiveMinimum(myArray, startSubScript, size-1);
system("pause");
}
int recursiveMinimum( const int myArray[], int ss, int es)
{
static int smallest = myArray[0];
if (smallest > myArray[ss])
smallest = myArray[ss];
return smallest;
if (ss == es)
return smallest;
else
recursiveMinimum(myArray, ss+1, es);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.