thrust

◆ stable_sort() [2/4]

template<typename RandomAccessIterator >
void thrust::stable_sort ( RandomAccessIterator  first,
RandomAccessIterator  last 
)

stable_sort is much like sort: it sorts the elements in [first, last) into ascending order, meaning that if i and j are any two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.

As the name suggests, stable_sort is stable: it preserves the relative ordering of equivalent elements. That is, if x and y are elements in [first, last) such that x precedes y, and if the two elements are equivalent (neither x < y nor y < x) then a postcondition of stable_sort is that x still precedes y.

This version of stable_sort compares objects using operator<.

Parameters
firstThe beginning of the sequence.
lastThe end of the sequence.
Template Parameters
RandomAccessIteratoris a model of Random Access Iterator, RandomAccessIterator is mutable, and RandomAccessIterator's value_type is a model of LessThan Comparable, and the ordering relation on RandomAccessIterator's value_type is a strict weak ordering, as defined in the LessThan Comparable requirements.

The following code snippet demonstrates how to use sort to sort a sequence of integers.

#include <thrust/sort.h>
...
const int N = 6;
int A[N] = {1, 4, 2, 8, 5, 7};
// A is now {1, 2, 4, 5, 7, 8}
See also
http://www.sgi.com/tech/stl/stable_sort.html
sort
stable_sort_by_key