方法:
min_element
和max_element
输入参数为vector
迭代器,输出为单一元素迭代器
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int> a = { 2,4,6,7,1,0,8,9,6,3,2 };
auto maxPosition = max_element(a.begin(), a.end());
auto minPosition = min_element(a.begin(), a.end());
cout << *maxPosition << " at the postion of " << maxPosition - a.begin() <<endl;
cout << *minPosition << " at the postion of " << minPosition - a.begin() <<endl;
system("pause");
return 0;
}