C++ algorithm is_sorted() function
Example
Find out if a vector is sorted:
vector<int> numbers = {1, 2, 3, 5, 7, 9};
if (is_sorted(numbers.begin(), numbers.end())) {
cout << "Sorted";
} else {
cout << "Not sorted";
}
Try it Yourself »
Definition and Usage
The is_sorted()
function checks if a data range is sorted in ascending order.
The data range is specified by iterators.
Syntax
is_sorted(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: | A boolean value:
|
---|
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.
Read more about booleans in our Booleans Tutorial.