标签:
min_element()和max_element
头文件:#include<algorithm>
作用:返回容器中最小值和最大值。max_element(first,end,cmp);其中cmp为可选择参数!
闲言少叙,上代码,一看就懂:
#include<iostream> #include<algorithm> using namespace std; bool cmp(int a,int b) { return a<b; } int main() { int num[]={2,3,1,6,4,5}; cout<<"最小值是 "<<*min_element(num,num+6)<<endl; cout<<"最大值是 "<<*max_element(num,num+6)<<endl; cout<<"最小值是 "<<*min_element(num,num+6,cmp)<<endl; cout<<"最大值是 "<<*max_element(num,num+6,cmp)<<endl; return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
STL之min_element()与max_element()(取容器中的最大最小值)
标签:
原文地址:http://blog.csdn.net/zwj1452267376/article/details/46777235