thrust::stable_sort
Defined in thrust/sort.h
-
template<typename RandomAccessIterator>
void thrust::stable_sort(RandomAccessIterator first, RandomAccessIterator last) stable_sort
is much likesort:
it sorts the elements in[first, last)
into ascending order, meaning that ifi
andj
are any two valid iterators in[first, last)
such thati
precedesj
, 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, ifx
andy
are elements in[first, last)
such thatx
precedesy
, and if the two elements are equivalent (neitherx < y
nory < x
) then a postcondition ofstable_sort
is thatx
still precedesy
.This version of
stable_sort
compares objects usingoperator<
.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}; thrust::stable_sort(A, A + N); // A is now {1, 2, 4, 5, 7, 8}
See also
sort
See also
stable_sort_by_key
- Parameters
first – The beginning of the sequence.
last – The end of the sequence.
- Template Parameters
RandomAccessIterator – is a model of Random Access Iterator,
RandomAccessIterator
is mutable, andRandomAccessIterator's
value_type
is a model of LessThan Comparable, and the ordering relation onRandomAccessIterator's
value_type
is a strict weak ordering, as defined in the LessThan Comparable requirements.