函数本身返回的是地址、需要用*取元素值
#include<bits/stdc++.h>
using namespace std;
struct Node{
int s;
bool operator<(const Node o)const{
return s < o.s;
}
}nodes[10];
/*
输出:
10
6
10
6
*/
int main()
{
int a[] = {3,2,4,7,5,9,10};
for(int i = 0; i < 7; ++i){
nodes[i].s = a[i];
}
vector<int> v(a,a+7); //用数组初始化 vector
cout << *max_element(v.begin(),v.end())<<endl;//求vector中最大值
cout << max_element(v.begin(),v.end())-v.begin()<<endl;//求出该最大值位置
cout << (*max_element(nodes,nodes+7)).s<<endl;//用于结构体 需要自定义比较 ,*取到的是一个结构体
cout << max_element(nodes,nodes+7)-nodes<<endl;//返回最大值所在位置 0开始
return 0;
}