⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 min_9233.htm

📁 ARM编辑、编译软件
💻 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>&copy;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 &#60;algorithm></PRE>
<PRE>
template &#60;class T>
 const T&#38; <B>min</B>(const T&#38;, const T&#38;);
template &#60;class T, class Compare>
 const T&#38; <B>min</B>(const T&#38; a, const T&#38;, 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&#60;</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 &#60;algorithm>  
 #include &#60;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&#60;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 &#60; operator, so using less here
   // is the same as using the max algorithm with a default
   // comparator.
   double val4 = max(d1, d2, less&#60;double>());    
   // val4 = 20 
   cout &#60;&#60; val1 &#60;&#60; " " &#60;&#60; val2 &#60;&#60; " " 
        &#60;&#60; val3 &#60;&#60; " " &#60;&#60; val4 &#60;&#60; 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 + -