help-gsl
[Top][All Lists]
Advanced

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

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


From: Matthew Boulton
Subject: Re: [Help-gsl] GSL Implementation of Quick Sort (or something better)
Date: Fri, 17 Aug 2007 10:58:04 +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

Could I use the cmp() function as the compare function? For example:

qsort( v->data , v->size , sizeof(double) , int(*cmp)( array_index , array_data ) )

Kind Regards,

Matt

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/
/ /




reply via email to

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