📄 max_element.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>max_element</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ Algorithms</a> > <a href= "max_element.html">max_element</a> </div> <div class="name-format"> max_element </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <algorithm> iterator max_element( iterator start, iterator end ); iterator max_element( iterator start, iterator end, BinPred p );</pre> <p>The max_element() function returns an iterator to the largest element in the range [<em>start</em>,<em>end</em>).</p> <p>If the binary predicate <em>p</em> is given, then it will be used instead of the < operator to determine the largest element.</p> <div class="related-examples-format"> Example code: </div> <div class="related-examples"> <p>For example, the following code uses the max_element() function to determine the largest integer in an array and the largest character in a vector of characters:</p> <pre class="example-code"> int array[] = { 3, 1, 4, 1, 5, 9 }; unsigned int array_size = 6; cout << "Max element in array is " << *max_element( array, array+array_size) << endl; vector<char> v; v.push_back('a'); v.push_back('b'); v.push_back('c'); v.push_back('d'); cout << "Max element in the vector v is " << *max_element( v.begin(), v.end() ) << endl; </pre> <p>When run, the above code displays this output:</p> <pre class="example-code"> Max element in array is 9 Max element in the vector v is d </pre> </div> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="max.html">max</a><br> <a href="min.html">min</a><br> <a href="min_element.html">min_element</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -