Sorting algorithms/Cycle sort: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: 'as' is now a keyword.)
(Added Easylang)
 
Line 792: Line 792:
[0, 0, 1, 1, 2, 2, 2, 2, 3.5, 4, 5, 6, 7, 8, 9]
[0, 0, 1, 1, 2, 2, 2, 2, 3.5, 4, 5, 6, 7, 8, 9]
using 10 writes.</pre>
using 10 writes.</pre>

=={{header|EasyLang}}==
<syntaxhighlight>
proc cyclesort . a[] .
for cs = 1 to len a[] - 1
item = a[cs]
pos = cs
for i = cs + 1 to len a[]
if a[i] < item
pos += 1
.
.
if pos <> cs
while item = a[pos]
pos += 1
.
t = a[pos]
a[pos] = item
item = t
while pos <> cs
pos = cs
for i = cs + 1 to len a[]
if a[i] < item
pos += 1
.
.
while item = a[pos]
pos += 1
.
t = a[pos]
a[pos] = item
item = t
.
.
.
.
d[] = [ 88 18 31 44 4 0 8 81 14 78 20 76 84 33 73 75 82 5 62 70 ]
cyclesort d[]
print d[]
</syntaxhighlight>
{{out}}
<pre>
[ 0 4 5 8 14 18 20 31 33 44 62 70 73 75 76 78 81 82 84 88 ]
</pre>


=={{header|Elixir}}==
=={{header|Elixir}}==