in reply to Re: bubble sort in perl
in thread bubble sort in perl
Okay, here's a somewhat more efficient numeric bubble sort. (taking a list instead of arrayref, just like perl's sort.)
sub bubble { my @array = @_; for my $i (0..$#array) { for my $j (0..$i) { @array[$i, $j] = @array[$j, $i] if $array[$i] < $array[$j]; } } return @array; }
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
|
|---|