max_element、min_element用法詳解

直接上代碼吧~

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a[4]={1,2,3,4};
	vector<int> v={1,2,3,4}; 
	int m1=*max_element(a,a+4);
	int m2=*min_element(v.begin(),v.end());
	printf("%d %d",m1,m2);
	return 0;
}

max_element返回指定容器或數組範圍[begin,end)內的最大值的迭代器或指針
min_element返回指定容器或數組範圍[begin,end)內的最小值的迭代器或指針
注意返回的是迭代器或指針哈~,不是直接返回值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章