Browse Source

refactoring: if there is only one data for the median just return that one

master
fdai7968 11 months ago
parent
commit
a10c7595f6
  1. 3
      src/average_median/average_median.c

3
src/average_median/average_median.c

@ -23,6 +23,9 @@ double median(double *data, int n) {
if (n==0) { if (n==0) {
return 0; return 0;
} }
else if (n==1){
return data[0];
}
else if (n % 2 == 0) { else if (n % 2 == 0) {
return (data[n / 2 - 1] + data[n / 2]) / 2.0; return (data[n / 2 - 1] + data[n / 2]) / 2.0;
} else { } else {

Loading…
Cancel
Save