From a10c7595f6a7f87fcb54cea2fb9c6513f894e9d9 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 18:43:08 +0000 Subject: [PATCH] refactoring: if there is only one data for the median just return that one --- src/average_median/average_median.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/average_median/average_median.c b/src/average_median/average_median.c index 0f7bca8..2b8b6b6 100644 --- a/src/average_median/average_median.c +++ b/src/average_median/average_median.c @@ -23,6 +23,9 @@ double median(double *data, int n) { if (n==0) { return 0; } + else if (n==1){ + return data[0]; + } else if (n % 2 == 0) { return (data[n / 2 - 1] + data[n / 2]) / 2.0; } else {