📄 min_9233.htm
字号:
<HTML><TITLE>min</TITLE><BODY>
<A HREF="ref.htm"><IMG SRC="images/banner.gif"></A>
<P><STRONG>Click on the banner to return to the Class Reference home page.</STRONG></P>
<P>©Copyright 1996 Rogue Wave Software</P>
<H2>min</H2>
<HR><PRE> Algorithm</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>Find and return the minimum of a pair of values</P>
<H3>Contents</H3>
<UL>
<A HREF="#Synopsis"><LI>Synopsis</LI></A>
<A HREF="#Description"><LI>Description</LI></A>
<A HREF="#Example"><LI>Example</LI></A>
<A HREF="#See Also"><LI>See Also</LI></A>
</UL>
<A NAME="Synopsis"><H3>Synopsis</H3></A>
<PRE>#include <algorithm></PRE>
<PRE>
template <class T>
const T& <B>min</B>(const T&, const T&);
template <class T, class Compare>
const T& <B>min</B>(const T& a, const T&, Compare);
</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P>The <B><I>min</B></I> algorithm determines and returns the minimum of a pair of values. In the second version of the algorithm, the optional argument <SAMP>Compare</SAMP> defines a comparison function that can be used in place of the default <SAMP>operator<</SAMP>. This function can be used with all the datatypes provided by the standard library.</P>
<P><B><I>min</B></I> returns the first argument when the two arguments are equal.</P>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// max.cpp
//
#include <algorithm>
#include <iostream.h>
int main(void)
{
double d1 = 10.0, d2 = 20.0;
<B> </B>// Find minimum
double val1 = <B>min</B>(d1, d2);
// val1 = 10.0
// the greater comparator returns the greater of the
// two values.
double val2 = <B>min</B>(d1, d2, greater<double>());
// val2 = 20.0;
// Find maximum
double val3 = max(d1, d2);
// val3 = 20.0;
// the less comparator returns the smaller of the
// two values.
// Note that, like every comparison in the STL, max is
// defined in terms of the < operator, so using less here
// is the same as using the max algorithm with a default
// comparator.
double val4 = max(d1, d2, less<double>());
// val4 = 20
cout << val1 << " " << val2 << " "
<< val3 << " " << val4 << endl;
return 0;
}
Output :
10 20 20 20
</PRE>
<A NAME="See Also"><H3>See Also</H3></A>
<P><A HREF="max_6671.htm"><B><I>max</B></I></A>, <A HREF="max_8656.htm"><B><I>max_element</B></I></A>, <A HREF="min_9998.htm"><B><I>min_element</B></I></A></P>
<HR>
<A HREF="mer_0626.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="min_9998.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -