thrust::is_sorted
Defined in thrust/sort.h
-
template<typename ForwardIterator>
bool thrust::is_sorted(ForwardIterator first, ForwardIterator last) is_sortedreturnstrueif the range[first, last)is sorted in ascending order, andfalseotherwise.Specifically, this version of
is_sortedreturnsfalseif for some iteratoriin the range[first, last - 1)the expression*(i + 1) < *iistrue.The following code demonstrates how to use
is_sortedto test whether the contents of adevice_vectorare stored in ascending order.#include <thrust/sort.h> #include <thrust/device_vector.h> #include <thrust/sort.h> ... thrust::device_vector<int> v(6); v[0] = 1; v[1] = 4; v[2] = 2; v[3] = 8; v[4] = 5; v[5] = 7; bool result = thrust::is_sorted(v.begin(), v.end()); // result == false thrust::sort(v.begin(), v.end()); result = thrust::is_sorted(v.begin(), v.end()); // result == true
See also
is_sorted_until
See also
sortSee also
stable_sortSee also
less<T>- Parameters
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters
ForwardIterator – is a model of Forward Iterator,
ForwardIterator'svalue_typeis a model of LessThan Comparable, and the ordering on objects ofForwardIterator'svalue_typeis a strict weak ordering, as defined in the LessThan Comparable requirements.- Returns
true, if the sequence is sorted;false, otherwise.