calc median g_

This commit is contained in:
olli 2024-08-16 22:51:45 +02:00
parent 4f2f11bd1a
commit 9d5f5eac9f

View File

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