27
27
===========================================================================*/
29
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT (c) 1995 European Soutern Observatory
30
.COPYRIGHT (c) 1995 European Southern Observatory
33
33
.AUTHOR P.Grosbol, IPG/ESO
35
35
.KEYWORDS sort, heapsort
36
.COMMENT Algorithm is adapted from 'Numerical Recipes in C' p.247
36
.COMMENT Making use of heapsort.c module
37
37
.VERSION 1.0 1995-Mar-09 : Creation, PJG
38
.VERSION 2.0 2015-Feb-09 : Using heapsort module, PBA
38
39
-----------------------------------------------------------------------*/
41
45
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
46
.PURPOSE sort array in place using heapsort
45
49
int n; /* no. of elements in array */
46
50
float *ra; /* pointer to array to be sorted */
68
if (j<ir && ra[j]<ra[j+1]) ++j;
53
int *ia = (int*)malloc((size_t)n*sizeof(int));
55
heapSortFloat(n,ra,ia);
63
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
64
.PURPOSE compares doubles the way strncmp does
65
.RETURN integer value, negative if the first argument is "less" than
66
the second, zero if they are "equal", and positive if the first
67
argument is "greater".
68
-----------------------------------------------------------------------*/
70
return (int) (*(double*)a - *(double*)b);
76
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
.PURPOSE compares doubles the way strncmp does
78
.RETURN integer value, negative if the first argument is "less" than
79
the second, zero if they are "equal", and positive if the first
80
argument is "greater".
81
-----------------------------------------------------------------------*/
83
return (int) (*(float*)a - *(float*)b);
90
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91
.PURPOSE compares integers the way strncmp does
92
.RETURN integer value, negative if the first argument is "less" than
93
the second, zero if they are "equal", and positive if the first
94
argument is "greater".
95
-----------------------------------------------------------------------*/
97
return (int) (*(int*)a - *(int*)b);
100
void std_sorti(n, ra)
101
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102
.PURPOSE sort array in place using quicksort algorithm for stdlib.h
104
-----------------------------------------------------------------------*/
105
int n; /* no. of elements in array */
106
int *ra; /* pointer to array to be sorted */
108
qsort(ra, n, sizeof(int), compare_ints);
111
void std_sortf(n, ra)
112
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113
.PURPOSE sort array in place using quicksort algorithm for stdlib.h
115
-----------------------------------------------------------------------*/
116
int n; /* no. of elements in array */
117
float *ra; /* pointer to array to be sorted */
119
qsort(ra, n, sizeof(float), compare_floats);
122
void std_sortd(n, ra)
123
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124
.PURPOSE sort array in place using quicksort algorithm for stdlib.h
126
-----------------------------------------------------------------------*/
127
int n; /* no. of elements in array */
128
double *ra; /* pointer to array to be sorted */
130
// Calling STDLIB qsort
131
qsort(ra, n, sizeof(double), compare_doubles);
134
void quick_sort(n, ra)
135
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136
.PURPOSE sort array in place using heapsort
138
-----------------------------------------------------------------------*/
139
int n; /* no. of elements in array */
140
float *ra; /* pointer to array to be sorted */