algorithm - STL C++

minmax()

Declaration

template <class X>
pair minmax(
	const X& kxrItem1,
	const X& kxrItem2
);

Description

This function returns a pair that contains the smaller and larger of the two elements "kxrItem1" and "kxrItem2" as the first and second elements, respectively. The overloaded version uses the function "xComp" as a comparison function.

Header Include

#include <algorithm>

Overloads

template <class X,  class BinaryPred>
pair minmax(
	const X& kxrItem1,
	const X& kxrItem2,
	BinaryPred xComp
);

Example

#include <iostream>
#include <algorithm>

int main()
{
	using namespace std;

	const double kdPi = 3.141259;
	const double kdE = 2.71828;
	// Find the smaller and larger of two values
	pair<double, double> qMinMax = minmax(kdPi, kdE);
	cout << "The smaller of " << kdPi << " and " << kdE << " is ";
	cout << qMinMax.first << endl;
	cout << "The larger of " << kdPi << " and " << kdE << " is ";
	cout << qMinMax.second << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

minmax() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.