These algorithms use either the <
operator for the element type or the given comparison operation. The algorithms in the first group operate on values rather than sequences. The algorithms in the second set take a sequence that is denoted by input iterators.
min(val1, val2)
min(val1, val2, comp)
min(init_list)
min(init_list, comp)
max(val1, val2)
max(val1, val2, comp)
max(init_list)
max(init_list, comp)
Returns the minimum/maximum of val1
and val2
or the minimum/maximum value in the initializer_list
. The arguments must have exactly the same type as each other. Arguments and the return type are both references to const
, meaning that objects are not copied.
minmax(val1, val2)
minmax(val1, val2, comp)
minmax(init_list)
minmax(init_list, comp)
Returns a pair
(§ 11.2.3, p. 426) where the first
member is the smaller of the supplied values and the second
is the larger. The initializer_list
version returns a pair
in which the first
member is the smallest value in the list and the second
member is the largest.
min_element(beg, end)
min_element(beg, end, comp)
max_element(beg, end)
max_element(beg, end, comp)
minmax_element(beg, end)
minmax_element(beg, end, comp)
min_element
and max_element
return iterators referring to the smallest and largest element in the input sequence, respectively. minmax_element
returns a pair
whose first
member is the smallest element and whose second
member is the largest.
This algorithm compares two sequences based on the first unequal pair of elements. Uses either the <
operator for the element type or the given comparison operation. Both sequences are denoted by input iterators.
lexicographical_compare(beg1, end1, beg2, end2)
lexicographical_compare(beg1, end1, beg2, end2, comp)
Returns true
if the first sequence is lexicographically less than the second. Otherwise, returns false
. If one sequence is shorter than the other and all its elements match the corresponding elements in the longer sequence, then the shorter sequence is lexicographically smaller. If the sequences are the same size and the corresponding elements match, then neither is lexicographically less than the other.