max_element和min_element
来源:互联网 发布:js判断按钮是否被点击 编辑:程序博客网 时间:2024/05/21 12:20
max_element和min_element
max_element和min_element:
函数作用:返回最大值和最小值,max_element(first,end,cmp);其中cmp为可选择参数!
first, last:
Input iterators to the initial and final positions of the sequence to use. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
comp:
Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument is to be considered less than the second argument, and false otherwise.
示例程序:
01
//结构体,普通元素
02
#include <iostream>
03
#include <algorithm>
04
using
namespace
std;
05
06
bool
myfn(
int
i,
int
j) {
return
i<j; }
07
08
struct
myclass {
09
bool
operator() (
int
i,
int
j) {
return
i<j; }
10
} myobj;
11
12
int
main () {
13
int
myints[] = {3,7,2,5,6,4,9};
14
15
cout <<
"最小的元素是 :"
<< *min_element(myints,myints+7) << endl;
16
cout <<
"最大的元素是 :"
<< *max_element(myints,myints+7) << endl;
17
18
cout <<
"最小的元素是 :"
<< *min_element(myints,myints+7,myfn) << endl;
19
cout <<
"最大的元素是 :"
<< *max_element(myints,myints+7,myfn) << endl;
20
21
cout <<
"最小的元素是: "
<< *min_element(myints,myints+7,myobj) << endl;
22
cout <<
"最大的元素是"
: << *max_element(myints,myints+7,myobj) << endl;
23
24
return
0;
25
}
输出结果:
1
最小元素是 2
2
最大元素是 9
3
最小元素是 2
4
最大元素是 9
5
最小元素是 2
6
最大元素是 9
0 0
- min_element和max_element
- max_element和min_element
- stl min_element和max_element
- min_element 和max_element
- *max_element函数和*min_element函数
- C++中max_element和min_element
- max_element和min_element的用法
- max_element和min_element的用法
- sort函数、max_element和min_element函数
- C++: *max_element函数和*min_element函数
- max_element、min_element、accumulate
- max_element/min_element详解
- min_element()与max_element()
- c++ min_element max_element
- STL max_element,min_element
- STL 之count,count_if,max,max_element,min,min_element和random_shuffle
- C++笔记——std::min_element和std::max_element
- STL 之count,count_if,max,max_element,min,min_element和random_shuffle
- MIME 参考
- 深入思考SDN的核心本质:从SDN=OpenFlow回到软件定义网络
- javascript面向对象编程
- d/D g/G h/H n/N p/P 你真的了解它们的区别吗?
- Android系统镜像文件的打包过程分析
- max_element和min_element
- 快速排序(python)
- leetcode刷题-题目2:逆波兰表达式计算
- vim的配置文件在哪?
- 微信js 大转盘抽奖
- 大康师傅你死定了
- ResourceProperties
- Python的函数参数传递:传值?引用?
- hive中使用sql语句需要注意的事项