calc median g_

This commit is contained in:
olli 2024-08-16 22:42:16 +02:00
parent d61329011b
commit 4f2f11bd1a

View File

@ -11,15 +11,15 @@ function g_median {
local g_num_elements=${#g_sorted_numbers[@]}
# calculate the middle
local g_middle=$((num_elements/2))
local g_middle=$((g_num_elements/2))
local g_median
# Falls die Anzahl der Elemente ungerade ist
if ((g_num_elements % 2 == 1)); then
g_median=${sorted_numbers[middle]}
g_median=${g_sorted_numbers[g_middle]}
else
# Falls die Anzahl der Elemente gerade ist
g_calc "(${sorted_numbers[middle - 1]} + ${sorted_numbers[middle]}) / 2"
g_calc "(${g_sorted_numbers[g_middle - 1]} + ${g_sorted_numbers[g_middle]}) / 2"
g_median=$g_calc_result
fi