thrust::stable_sort
Defined in thrust/sort.h
- 
template<typename RandomAccessIterator, typename StrictWeakOrdering>
 void thrust::stable_sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)
- 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 a function object- comp.- The following code demonstrates how to sort integers in descending order using the greater<int> comparison operator. - #include <thrust/sort.h> #include <thrust/functional.h> ... const int N = 6; int A[N] = {1, 4, 2, 8, 5, 7}; thrust::sort(A, A + N, thrust::greater<int>()); // A is now {8, 7, 5, 4, 2, 1}; - See also - sort- See also - stable_sort_by_key- Parameters
- first – The beginning of the sequence. 
- last – The end of the sequence. 
- comp – Comparison operator. 
 
- Template Parameters
- RandomAccessIterator – is a model of Random Access Iterator, - RandomAccessIteratoris mutable, and- RandomAccessIterator's- value_typeis convertible to- StrictWeakOrdering'sfirst argument type and second argument type.
- StrictWeakOrdering – is a model of Strict Weak Ordering.