stl:algorithm:max

C++ Reference

max

Syntax:

    #include <algorithm>
    const TYPE& max( const TYPE& x, const TYPE& y );
    const TYPE& max( const TYPE& x, const TYPE& y, BinPred p );

The max() function returns the greater of x and y.

If the binary predicate p is given, then it will be used instead of the < operator to compare the two elements.

For example, the following code snippet displays various uses of the max() function:

   cout << "Max of 1 and 9999 is " << max( 1, 9999) << endl;
   cout << "Max of 'a' and 'b' is " << max( 'a', 'b') << endl;
   cout << "Max of 3.14159 and 2.71828 is " << max( 3.14159, 2.71828) << endl;

When run, this code displays:

   Max of 1 and 9999 is 9999
   Max of 'a' and 'b' is b
   Max of 3.14159 and 2.71828 is 3.14159

Related Topics: max_element, min, min_element