In C ++ max_element
, if there are several elements that are maximal, it returns the first such element. While minmax_element
(C ++ 11) returns the last max element.
Is there a reason for standards for this behavior?
From cplusplus.com
If more than one equivalent element has the highest value, the second iterator points to the last of these elements.
The comparison is performed using any operator <for the first version, or for the second; An element is the largest if no other element is compared with it less. If more than one element satisfies this condition, the iterator returns points to the first of such elements.
source share