Sorting Algorithms/Circle Sort: Difference between revisions

Added Julia language
m (→‎{{header|Fortran}}: Correct capitalization of language name so it is categorized properly)
(Added Julia language)
Line 553:
<lang sh>$ jq -n -c -f -M circleSort.jq
["The","brown","dog","fox","jumps","lazy","over","quick","the"]</lang>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<lang julia>function _ciclesort!(arr::Vector, lo::Int, hi::Int, swaps::Int)
lo == hi && return swaps
high = hi
low = lo
mid = (hi - lo) ÷ 2
while lo < hi
if arr[lo] > arr[hi]
arr[lo], arr[hi] = arr[hi], arr[lo]
swaps += 1
end
lo += 1
hi -= 1
end
if lo == hi
if arr[lo] > arr[hi+1]
arr[lo], arr[hi+1] = arr[hi+1], arr[lo]
swaps += 1
end
end
swaps = _ciclesort!(arr, low, low + mid, swaps)
swaps = _ciclesort!(arr, low + mid + 1, high, swaps)
return swaps
end
 
function ciclesort!(arr::Vector)
while !iszero(_ciclesort!(arr, 1, endof(arr), 0)) end
return arr
end
 
v = rand(10)
println("# $v\n -> ", ciclesort!(v))</lang>
 
{{out}}
<pre># [0.603704, 0.293639, 0.51395, 0.74624, 0.245282, 0.930508, 0.550865, 0.62253, 0.00608894, 0.270426]
-> [0.00608894, 0.245282, 0.270426, 0.293639, 0.51395, 0.550865, 0.603704, 0.62253, 0.74624, 0.930508]</pre>
 
=={{header|Kotlin}}==
Anonymous user