STL min_element and max_element in C++
Level 4212 keystrokes
Finds the smallest and largest elements of a vector with min_element and max_element, which return iterators, and prints Min: 1 and Max: 9.
C++ code
1vector<int> nums = {5, 2, 8, 1, 9, 3};// min_element returns an iterator to the smallest element, not the value2auto minIt = min_element(nums.begin(), nums.end());// max_element does the same for the largest element3auto maxIt = max_element(nums.begin(), nums.end());// Dereference the iterator to get the value: prints Min: 14cout << "Min: " << *minIt << endl;// Prints Max: 95cout << "Max: " << *maxIt << endl;Output
Min: 1 Max: 9
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 13,× 7(× 6)× 6;× 5.× 4"× 4=× 3_× 2:× 2