Sorting algorithms/Stooge sort: Difference between revisions

Added Julia language
(Add Common Lisp implementation)
(Added Julia language)
Line 841:
[1,2,3,4]
[-6,-5,-2,1,3,3,4,5,7,10]</lang>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{trans|Matlab}}
<lang julia>function stoogesort!(a::Array, i::Int=1, j::Int=length(a))
if a[j] < a[i]
a[[i, j]] = a[[j, i]];
end
 
if (j - i) > 1
t = round(Int, (j - i + 1) / 3)
a = stoogesort!(a, i, j - t)
a = stoogesort!(a, i + t, j)
a = stoogesort!(a, i, j - t)
end
 
return a
end
 
x = randn(10)
@show x stoogesort!(x)</lang>
 
{{out}}
<pre>x = [0.222881, -1.06902, -1.07703, 0.466872, 1.52261, -0.25279, -1.72147, -0.217577, -0.556917, 2.13601]
stoogesort!(x) = [-1.72147, -1.07703, -1.06902, -0.556917, -0.25279, -0.217577, 0.222881, 0.466872, 1.52261, 2.13601]</pre>
 
=={{header|Kotlin}}==
Anonymous user