Sorting algorithms/Strand sort: Difference between revisions

m (→‎{{header|REXX}}: changed style of '''output'''. -- ~~~~)
Line 734:
say "After @a";</lang>
=={{header|Perl 6}}==
<lang perl6>sub mergeinfix:<M> (@x, @y) {
gather {
while @x and @y {
Line 747:
}
 
sub strand (@x is rw) {
my $i = 0;
my $prev = -Inf;
my $i = 0;
gather while $i < @x {
if @x[$i] !before $prev {
take $prev = splice(@x, $i++, 1)[0];
}
else {
take $prev = splice(@x,$i,1)[0]++;
}
}
}
 
sub strand-sortstrand_sort (@x is copy) {
my @out;
@out M= merge(@out, strand(@x)) while @x;
@out;
}
 
my @a = (^100).roll(2010);
say "Before @a[]";
@a = strand-sortstrand_sort(@a);
say "After @a[]";
 
@a = <The quick brown fox jumps over the lazy dog's back.>;
say "Before @a[]";
@a = strand-sortstrand_sort(@a);
say "After @a[]";</lang>
{{out}}
Anonymous user