Sorting algorithms/Strand sort: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: corrected a stray question mark. -- ~~~~)
m (→‎{{header|Perl 6}}: minor simplfications)
Line 790: Line 790:
my $i = 0;
my $i = 0;
gather while $i < @x {
gather while $i < @x {
if @x[$i] !before $prev {
if @x[$i] before $prev {
take $prev = splice(@x, $i, 1)[0];
}
else {
$i++;
$i++;
}
else {
take $prev = splice(@x, $i, 1)[0];
}
}
}
}
Line 810: Line 810:
say "After @a[]";
say "After @a[]";


@a = <The quick brown fox jumps over the lazy dog's back.>;
@a = <The quick brown fox jumps over the lazy dog>;
say "Before @a[]";
say "Before @a[]";
@a = strand_sort(@a);
@a = strand_sort(@a);
Line 817: Line 817:
<pre>Before 1 20 64 72 48 75 96 55 42 74
<pre>Before 1 20 64 72 48 75 96 55 42 74
After 1 20 42 48 55 64 72 74 75 96
After 1 20 42 48 55 64 72 74 75 96
Before The quick brown fox jumps over the lazy dog's back.
Before The quick brown fox jumps over the lazy dog
After The back. brown dog's fox jumps lazy over quick the</pre>
After The brown dog fox jumps lazy over quick the</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==