C++ Algorithm is_sorted()C++ Algorithm is_sorted() function returns true if the elements in the range [first, last) are sorted into ascending order. The elements are compared using operator < for the first version, and comp for the second version. SyntaxParameterfirst: An forward iterator pointing to the first element in the range to be checked. last: An random access iterator pointing to the past last element in the range to be checked. comp: A user defined binary predicate function that accepts two arguments and returns true if the two arguments are in order and false otherwise. It follows the strict weak ordering to order the elements. Return valueIt returns true if the range [first, last) is sorted into ascending order, false otherwise. ComplexityThe Complexity is linear in the distance between first and last: compares pairs of elements until a mismatch is found. Data racesThe object in the range [first, last) are accessed. ExceptionsThis function throws an exception if either an element comparison, or an operation on iterator throws an exception. Note: The invalid parameters cause an undefined behavior.
|