thrust::stable_sort
Defined in thrust/sort.h
- 
template<typename DerivedPolicy, typename RandomAccessIterator>
 void thrust::stable_sort(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, RandomAccessIterator first, RandomAccessIterator last)
- stable_sortis much like- sort:it sorts the elements in- [first, last)into ascending order, meaning that if- iand- jare any two valid iterators in- [first, last)such that- iprecedes- j, then- *jis not less than- *i.- As the name suggests, - stable_sortis stable: it preserves the relative ordering of equivalent elements. That is, if- xand- yare elements in- [first, last)such that- xprecedes- y, and if the two elements are equivalent (neither- x < ynor- y < x) then a postcondition of- stable_sortis that- xstill precedes- y.- This version of - stable_sortcompares objects using- operator<.- The algorithm’s execution is parallelized as determined by - exec.- The following code snippet demonstrates how to use - sortto sort a sequence of integers using the- thrust::hostexecution policy for parallelization:- #include <thrust/sort.h> #include <thrust/execution_policy.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::stable_sort(thrust::host, A, A + N); // A is now {1, 2, 4, 5, 7, 8} - See also - sort- See also - stable_sort_by_key- Parameters
- exec – The execution policy to use for parallelization. 
- first – The beginning of the sequence. 
- last – The end of the sequence. 
 
- Template Parameters
- DerivedPolicy – The name of the derived execution policy. 
- RandomAccessIterator – is a model of Random Access Iterator, - RandomAccessIteratoris mutable, and- RandomAccessIterator's- value_typeis a model of LessThan Comparable, and the ordering relation on- RandomAccessIterator's- value_typeis a strict weak ordering, as defined in the LessThan Comparable requirements.