Template Function thrust::sort(RandomAccessIterator, RandomAccessIterator)¶
Function Documentation¶
-
template<typename
RandomAccessIterator>
voidthrust::sort(RandomAccessIterator first, RandomAccessIterator last) sortsorts the elements in[first, last)into ascending order, meaning that ifiandjare any two valid iterators in[first, last)such thatiprecedesj, then*jis not less than*i. Note:sortis not guaranteed to be stable. That is, suppose that*iand*jare equivalent: neither one is less than the other. It is not guaranteed that the relative order of these two elements will be preserved bysort.This version of
sortcompares objects usingoperator<.The following code snippet demonstrates how to use
sortto sort a sequence of integers.- Parameters
first: The beginning of the sequence.last: The end of the sequence.
- Template Parameters
RandomAccessIterator: is a model of Random Access Iterator,RandomAccessIteratoris mutable, andRandomAccessIterator'svalue_typeis a model of LessThan Comparable, and the ordering relation onRandomAccessIterator'svalue_typeis a strict weak ordering, as defined in the LessThan Comparable requirements.
#include <thrust/sort.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(A, A + N); // A is now {1, 2, 4, 5, 7, 8}
- See
- See
stable_sort- See
sort_by_key