Jump to content

Sorting algorithms/Strand sort: Difference between revisions

m
→‎{{header|Perl 6}}: fixed merge routine
(→‎{{header|Perl 6}}: Mark as broken)
m (→‎{{header|Perl 6}}: fixed merge routine)
Line 1,072:
 
=={{header|Perl 6}}==
{{Works with|Rakudo|2018.04.01}}
{{broken|Perl 6}}
<lang perl6>sub infix:<M> (@x-in, @y-in) {
gathermy {@x = | @x-in;
while @x and my @y {= | @y-in;
take do givenflat @x[0] cmp, @y[0] {,
reverse gather while @x and @y {
when Increase { @x.shift }
take $prevdo =given splice(@x,[*-1] $i,cmp 1)@y[0*-1]; {
when Decrease { @y.shift }
when Same when More { @x.shift,pop @y.shiftx }
when Less { pop @y }
}
when Same { pop(@x), pop(@y) }
}
}
take @x, @y;
}
}
 
sub strand (@x is rw) {
my $i = 0;
my $prev = -Inf;
my $i = 0;
gather while $i < @x {
if @x[$i] before $prev {?? $i++ !! take $prev = splice(@x, $i, 1)[0];
$i++;
}
else {
take $prev = splice(@x, $i, 1)[0];
}
}
}
Line 1,106 ⟶ 1,101:
 
my @a = (^100).roll(10);
say "Before {@a[]}";
@a = strand_sort(@a);
say "After {@a[]}";
 
@a = <The quick brown fox jumps over the lazy dog>;
say "Before {@a[]}";
@a = strand_sort(@a);
say "After {@a[]}";</lang>
{{out}}
<pre>Before 1 20 64 72 48 75 96 55 42 74
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.