calc median g_
This commit is contained in:
parent
d61329011b
commit
4f2f11bd1a
@ -11,15 +11,15 @@ function g_median {
|
|||||||
local g_num_elements=${#g_sorted_numbers[@]}
|
local g_num_elements=${#g_sorted_numbers[@]}
|
||||||
|
|
||||||
# calculate the middle
|
# calculate the middle
|
||||||
local g_middle=$((num_elements/2))
|
local g_middle=$((g_num_elements/2))
|
||||||
|
|
||||||
local g_median
|
local g_median
|
||||||
# Falls die Anzahl der Elemente ungerade ist
|
# Falls die Anzahl der Elemente ungerade ist
|
||||||
if ((g_num_elements % 2 == 1)); then
|
if ((g_num_elements % 2 == 1)); then
|
||||||
g_median=${sorted_numbers[middle]}
|
g_median=${g_sorted_numbers[g_middle]}
|
||||||
else
|
else
|
||||||
# Falls die Anzahl der Elemente gerade ist
|
# 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
|
g_median=$g_calc_result
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user