[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] GSL Implementation of Quick Sort (or something better)
From: |
Patrick Alken |
Subject: |
Re: [Help-gsl] GSL Implementation of Quick Sort (or something better) |
Date: |
Thu, 16 Aug 2007 12:02:59 -0600 |
User-agent: |
Mutt/1.4.2.2i |
why not use the qsort(3) function?
if you have a gsl_vector *v:
qsort(v->data, v->size, sizeof(double), &compare)
where you would just have to write the compare function.
On Thu, Aug 16, 2007 at 05:10:00PM +0100, Matthew Boulton wrote:
> Hello. I've got some quick sort code that is now reading in data from
> GSl vectors, and so I was wondering if there is a GSL implementation of
> the quick sort algorithm given below:
>
> --quick_sort.c
>
> #include "common.h"
>
> void quick_sort (DATA_TYPE *list, int *index, int n){
>
> int i;
> void quick_sort_1();
>
> for ( i = 0; i < n; i++ ) index [i]=i;
> quick_sort_1 ( list , index , 0 , n-1 );
>
> return;
>
> }
>
> -- quick_sort_1.c
>
> #include "common.h"
>
> void quick_sort_1(DATA_TYPE *list, int *index, int left_end, int right_end)
>
> {
>
> int i, j, temp;
> DATA_TYPE chosen;
>
> chosen = list[ index[ (left_end + right_end) / 2 ] ];
> i = (left_end - 1);
> j = (right_end + 1);
>
> for (;;)
>
> {
>
> while (list [index[++i]] < chosen);
> while (list [index[--j]] > chosen);
>
> if (i < j)
>
> {
>
> temp = index [j];
> index [j] = index [i];
> index [i] = temp;
>
> }
>
> else if (i==j)
>
> {
>
> ++i;
> break;
>
> }
>
> else break;
>
> }
>
> if (left_end < j) quick_sort_1 (list, index, left_end, j);
> if (i < right_end) quick_sort_1 (list, index, i, right_end);
>
> return;
>
> }
>
> which looks like a fairly standard quick sort algorithm. If there is no
> GSL quick sort algorithm, then would the GSL heapsort algorithm easily
> take the place of the above quick sort function?
>
> Kind Regards,
>
> Matt
>
>
>
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
>