Algorithm测试
#include <algorithm> #include <vector> #include <iostream> using namespace std; int main() { vector<int> vec_1 = {3,7,6,2,1,8,9}; auto minpos = min_element(vec_1.cbegin(), vec_1.cend()); vector<int>::iterator vec_min_iter = min_element(vec_1.begin(), vec_1.end()); cout << "min value: " << *minpos << " " << *vec_min_iter << endl; auto maxpos = max_element(vec_1.cbegin(), vec_1.cend()); vector<int>::iterator vec_max_iter = max_element(vec_1.begin(), vec_1.end()); cout << "max value: " << *maxpos << " " << *vec_max_iter << endl; system("pause"); return 0; }
min value: 1 1
max value: 9 9
请按任意键继续. . .