max_element()与min_element()

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int i,int j)
{
return i<j;
}
struct myclass
{
bool operator()(int i,int j)
{
return i<j;
}
}myobj;
int main()
{
int a[] = {7,1,6,4,9,2};
//不用cmp参数
cout << *min_element(a,a+6)<<endl;//1
cout << *max_element(a,a+6)<<endl;//9
//用方法做cmp参数
cout << *min_element(a,a+6,cmp)<<endl;//1
cout << *max_element(a,a+6,cmp)<<endl;//9
//用结构体做cmp参数
cout << *min_element(a,a+6,myobj)<<endl;//1
cout << *max_element(a,a+6,myobj)<<endl;//9
return 0;
}

posted @ 2018-08-17 19:43  敲代码不BB  阅读(175)  评论(0编辑  收藏  举报