Sorting algorithms/Cocktail sort: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎version handles non-blanks: De-obfuscate Rexx version)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(2 intermediate revisions by 2 users not shown)
Line 1,742:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
import system'math;
Line 1,758:
swapped := false;
for(int i := 0,; i <= list.Length - 2,; i += 1)
{
if (list[i]>list[i+1])
Line 1,772:
swapped := false;
for(int i := list.Length - 2,; i >= 0,; i -= 1)
{
if (list[i]>list[i+1])
Line 3,787:
===version handles non-blanks===
This faster REXX version can handle array elements that don't contain blanks or spaces by using a simpler ''swap'' mechanism.
The REXX ''PARSE'' instruction separates an input into parts and assigns them to
variables, in a single operation. Thus
<syntaxhighlight lang="rexx">PARSE VALUE 0 items.j items.jp WITH done items.jp items.j</syntaxhighlight>
sets ''done'' to 0, ''items.jp'' to ''items.j'', and ''items.j'' to ''items.jp'', as long as none of the input
variables contain any blanks.
<syntaxhighlight lang="rexx">cocktailSort2: procedure expose items.
nn = items.0 - 1 /*N: the number of items in items.*/
Line 4,447 ⟶ 4,452:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var cocktailSort = Fn.new { |a|
var last = a.count - 1
while (true) {
9,476

edits