Averages/Median: Difference between revisions
m
→{{header|EasyLang}}
(Initial FutureBasic task solution added) |
|||
Line 2,485:
<syntaxhighlight lang="text">
proc quickselect k . list[] res .
#
subr partition
mid = left
for i = left + 1 to right
if list[i] < list[left]
mid += 1
swap list[i] list[mid]
.▼
.
swap list[left] list[mid]▼
▲ .
.▼
▲ swap list[left] list[mid]
▲ .
while left < right
right = len list[]▼
partition
▲ while left < right
left = right
.
proc median . list[] res .
h = len list[] div 2 + 1
if len list[] mod 2 = 0
res = (res + h) / 2
.
.
test[] = [ 4.1 5.6 7.2 1.7 9.3 4.4 3.2 ]
print med
test[] = [ 4.1 7.2 1.7 9.3 4.4 3.2 ]
print med
</syntaxhighlight>
|