Sort three variables: Difference between revisions

m
Formatting.
(add FreeBASIC)
m (Formatting.)
Line 1,804:
=={{header|Nim}}==
<lang nim>
proc sortthreesortThree[T](a, b, c: var T) =
#bubble Bubble sort, why not?
while not (a <= b and b <= c):
if a > b: swap a, b
if b > c: swap b, c
 
proc testwithtestWith[T](a, b, c: T) =
var (x, y, z) = (a, b, c)
echo "Before: ", x, ", ", y, ", ", z
sortthreesortThree(x, y, z)
echo "After: ", x, ", ", y, ", ", z
 
testwithtestWith(6, 4, 2)
testwithtestWith(0.9, -37.1, 4.0)
testwithtestWith("lions", "tigers", "bears")</lang>
 
testwith(6,4,2)
testwith(0.9,-37.1,4.0)
testwith("lions","tigers","bears")</lang>
{{out}}
<pre>Before: 6, 4, 2
Anonymous user