calc median g_
This commit is contained in:
parent
9d5f5eac9f
commit
4174b3f7e3
@ -13,14 +13,18 @@ function g_median {
|
||||
# calculate the middle
|
||||
local g_middle=$((g_num_elements/2))
|
||||
|
||||
# local g_median
|
||||
# if ((g_num_elements % 2 == 1))
|
||||
# then
|
||||
# g_median=${g_sorted_numbers[g_middle]}
|
||||
# else
|
||||
# g_calc "(${g_sorted_numbers[g_middle - 1]} + ${g_sorted_numbers[g_middle]}) / 2"
|
||||
# g_median=$g_calc_result
|
||||
# fi
|
||||
local g_median
|
||||
# even/odd number
|
||||
if ((g_num_elements % 2 == 1))
|
||||
then
|
||||
# odd number
|
||||
echo "g_middle=$g_middle"
|
||||
g_median=${g_sorted_numbers[g_middle]}
|
||||
else
|
||||
# even number
|
||||
g_calc "(${g_sorted_numbers[g_middle - 1]} + ${g_sorted_numbers[g_middle]}) / 2"
|
||||
g_median=$g_calc_result
|
||||
fi
|
||||
|
||||
g_median_result=${g_sorted_numbers[g_middle]}
|
||||
g_median_result=$g_median
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user