2
* Copyright (C) 2004-2007 by the GRASS Development Team
3
* Author(s): 1998, 1999 Sebastian Cyris
4
* 2007 modified by Soeren Gebbert
6
* This program is free software under the GNU General Public
7
* License (>=v2). Read the file COPYING that comes with GRASS
13
static void downheap_int(int *array, int n, int k);
14
static void downheap_float(float *array, int n, int k);
15
static void downheap_double(double *array, int n, int k);
17
/* *************************************************************** */
18
/* *************************************************************** */
19
/* *************************************************************** */
20
void downheap_int(int *array, int n, int k)
28
if (j < n && array[j] < array[j + 1])
40
/* *************************************************************** */
41
/* *************************************************************** */
42
/* *************************************************************** */
43
void downheap_float(float *array, int n, int k)
52
if (j < n && array[j] < array[j + 1])
64
/* *************************************************************** */
65
/* *************************************************************** */
66
/* *************************************************************** */
67
void downheap_double(double *array, int n, int k)
76
if (j < n && array[j] < array[j + 1])
88
/* *************************************************************** */
89
/* ****** heapsort for int arrays of size n ********************** */
90
/* *************************************************************** */
91
void heapsort_int(int *array, int n)
97
for (k = n / 2; k >= 0; k--)
98
downheap_int(array, n, k);
104
downheap_int(array, --n, 0);
110
/* *************************************************************** */
111
/* ****** heapsort for float arrays of size n ******************** */
112
/* *************************************************************** */
113
void heapsort_float(float *array, int n)
120
for (k = n / 2; k >= 0; k--)
121
downheap_float(array, n, k);
127
downheap_float(array, --n, 0);
132
/* *************************************************************** */
133
/* ****** heapsort for double arrays of size n ******************* */
134
/* *************************************************************** */
135
void heapsort_double(double *array, int n)
142
for (k = n / 2; k >= 0; k--)
143
downheap_double(array, n, k);
149
downheap_double(array, --n, 0);