/*
* Comparison function for use with qsort
*
* @param a First value for comparison
* @param b Second value for comparison
* @return a-b : the result of the comparison
*/
int qsort_compare(const int *a, const int *b) {
return (int)(*a - *b);
}
/*
* Find the median some values
*
* @param values pointer to the values of which to find the median
* @param n number of values
* @return Returns the median value
*/
static int median(int *values, int n) {
int temp[9]; // largest n used for median calculation is 9
int i;
for(i=0; i<n; i++) {
temp[i] = values[i];
}
qsort(temp, n, sizeof(int), qsort_compare);
return(temp[ n>>1 ]);
}