template < class T >
T minimum ( T value1, T value2)
{
T minimumValue = value1;
if (value2 < minimumValue)
minimumValue = value2;
return minimumValue;
}
Now, I'm not using recursion. I'm not supposed to. This is for homework and my brain is going crazy! I don't know how to turn the code I already made into using it to find the minimum in vectors. Can someone point me in the right direction?
You need a loop. Assume that the minimum value is the first one in the vector. Then, compare the second value
against that minimum. If the second value is less than your assumed minimum, then assume that the second value
is the minimum. Repeat for the 3rd element, then 4th element, and so forth until you compare the last element.
At that point, your assumed minimum is the minimum value.
If that is not helpful enough, there are a number of posts around here regarding finding the minimum or maximum
values in an array/vector.