[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Sorting using "_index" version

From: Hongzheng Wang
Subject: Re: [Help-gsl] Sorting using "_index" version
Date: Wed, 23 Jun 2010 14:04:20 +0800

On Wed, Jun 23, 2010 at 12:35 AM, Vicent <address@hidden> wrote:
> Hello to all.
> I have to sort several arrays of double data, but I am thinking about using
> the "_index" version of the functions in the GSL, because I want to keep the
> original array unchanged.
> In the documentation of GSL it is said the following when speaking about the
> "gsl_heapsort" function:
> """The following function provides a simple alternative to the standard
> library function qsort.
> It is intended for systems lacking qsort, not as a replacement for it. The
> function qsort
> should be used whenever possible, as it will be faster and can provide
> stable ordering of
> equal elements. Documentation for qsort is available in the GNU C Library
> Reference
> Manual."""
> I have also found "qsort_s" in C++ (an enhanced or more secure version of
> "qsort").
> Anyway, my question is: Is there any "standard" function in C++ similar to
> those "_index" sorting functions in GSL?? I mean, a sorting function that
> gives a permutation as a result, but keeps the original vector or array
> unchanged.
> I think I am going to use "gsl_sort_index", but I want to be sure first,
> because of the warning about "gsl_heapsort" I talked about.
> Thank you in advance for your help, your answers and your patience!
> --
> Vicent
> _______________________________________________
> Help-gsl mailing list
> address@hidden

Hi Vicent,

I think you are looking for indirect sorting routines.  Indirect sort
is usually used when the original records are large and complicated
and expensive for swapping.  With standard sorting routines, indirect
sort can be easily implemented by providing a `helper' array
containing the key fields of the original records and the
corresponding index and sorting the helper array.

In C++ the standard way to do sorting is the template-based sort
algorithms in header file <algorithm>:
template <class RandomAccessIterator>
  void sort ( RandomAccessIterator first, RandomAccessIterator last );

template <class RandomAccessIterator, class Compare>
  void sort ( RandomAccessIterator first, RandomAccessIterator last,
Compare comp );


reply via email to

[Prev in Thread] Current Thread [Next in Thread]