Anonymous user
Sorting algorithms/Shell sort: Difference between revisions
Added Julia language
(Added Kotlin) |
(Added Julia language) |
||
Line 1,305:
[]
[null,0,1,2,3,4.4,5,5]</lang>
=={{header|Julia}}==
{{trans|Java}}
<lang julia># v0.6
function shellsort!(a::Array{Int})::Array{Int}
incr = div(length(a), 2)
while incr > 0
for i in incr+1:length(a)
j = i
tmp = a[i]
while j > incr && a[j - incr] > tmp
a[j] = a[j-incr]
j -= incr
end
a[j] = tmp
end
if incr == 2
incr = 1
else
incr = floor(Int, incr * 5.0 / 11)
end
end
return a
end
x = rand(1:10, 10)
@show x shellsort!(x)
@assert issorted(x)</lang>
{{out}}
<pre>x = [2, 6, 9, 2, 3, 9, 5, 2, 5, 9]
shellsort!(x) = [2, 2, 2, 3, 5, 5, 6, 9, 9, 9]</pre>
=={{header|Kotlin}}==
|