Or login with:
#include <algorithm> template < class Type > const Type& min( const Type& left, const Type& right ); template < class Type, class Pr > const Type& min( const Type& left, const Type& right, BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| left | The first of the two objects being compared |
| right | The second of the two objects being compared |
| comp | A binary predicate used to compare the two objects |
operator< and the second compares objects using the function object comp.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { cout <<"\nFirst, we find the minimum of two integer literal values.\n"; cout <<"min(12, -3) = "<<min(12, -3); int first = 7; int second = 10; cout <<"\nNext, we find the minimum of two integer \nvalues stored in simple integer variables"; cout <<"\nfirst = "<<first<<" second = "<<second<<endl; cout <<"min(first, second) = "<<min(first, second); int a[] = {2, 6, 10, 8, 4}; vector<int> v(a, a+5); cout <<"\nHere are the integer values in the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nNow we find the minimum of the first and last values " "\nstored in the vector of integers using one approach."; cout <<"\nmin(v.at(0), v.at(4)) = "<<min(v.at(0), v.at(4)); cout <<"\nFinally, we find the minimum of the first and last values " "\nstored in the vector of integers using a second approach."; cout <<"\nmin(*v.begin(), *(v.end()-1)) = "<<min(*v.begin(), *(v.end()-1)); return 0; }
You must login to leave a messge