C++ algorithm is_sorted_until() function
Example
Count how many elements are in ascending order:
vector<int> numbers = {1, 7, 3, 5, 9, 2};
auto it = is_sorted_until(numbers.begin(), numbers.end());
int position = it - numbers.begin();
cout << "The first " << position << " items are in ascending order.";
Try it Yourself »
Definition and Usage
The is_sorted_until()
function returns an iterator pointing to the first element in a data range which does not have a greater value than the element before it. If all of the elements are sorted then the function returns the iterator pointing to the end of the data range.
The data range is specified by iterators.
Syntax
is_sorted_until(iterator start, iterator end);
Parameter Values
Parameter | Description |
---|---|
start | Required. An iterator pointing to the start of the data range. |
end | Required. An iterator pointing to the end of the data range. Elements up to this position will be included, but the element at this position will not be. |
Technical Details
Returns: | An iterator pointing to the first element in the data range which does not have a greater value than the element before it. If all of the elements are sorted then the function returns the end of the data range. |
---|
Related Pages
Read more about data structures in our Data Structures Tutorial.
Read more about iterators in our Iterators Tutorial.
Read more about algorithms in our Algorithms Tutorial.