calc median g_
This commit is contained in:
parent
9d5f5eac9f
commit
4174b3f7e3
@ -13,14 +13,18 @@ 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
|
||||||
# if ((g_num_elements % 2 == 1))
|
# even/odd number
|
||||||
# then
|
if ((g_num_elements % 2 == 1))
|
||||||
# g_median=${g_sorted_numbers[g_middle]}
|
then
|
||||||
# else
|
# odd number
|
||||||
# g_calc "(${g_sorted_numbers[g_middle - 1]} + ${g_sorted_numbers[g_middle]}) / 2"
|
echo "g_middle=$g_middle"
|
||||||
# g_median=$g_calc_result
|
g_median=${g_sorted_numbers[g_middle]}
|
||||||
# fi
|
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