help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] GSL Implementation of Quick Sort (or something better)


From: Matthew Boulton
Subject: [Help-gsl] GSL Implementation of Quick Sort (or something better)
Date: Thu, 16 Aug 2007 17:10:00 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060501 Fedora/1.7.13-1.1.fc5

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





reply via email to

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