2 * Based on Nicolas Devillard's work at
4 * http://ndevilla.free.fr/median/median/index.html
5 * http://ndevilla.free.fr/median/median/src/wirth.c
6 * ndevilla AT free DOT fr
10 * Algorithm from N. Wirth's book, implementation by N. Devillard.
11 * This code in public domain.
16 coord_median(coord_t
*values
, unsigned int n
)
19 int i
, j
; /* working bottom, top */
20 int bottom
= 0; /* window bottom */
21 int top
= n
- 1; /*window top */
23 if (! (n
& 1)){ /*return lower of 2 centre values */
27 while (bottom
< top
) {
31 while (values
[i
] < values
[middle
]){
34 while (values
[middle
] < values
[j
]){
38 coord_t tmp
= values
[i
];
39 values
[i
] = values
[j
];
53 return values
[middle
];