Usage: bbl_sort(\@array);
For the curious, sorting a 10,000 element array of unique numbers on my 1.2 Ghz Athlon takes about 3 minutes on a randomized array. The worst-case-scenario, with all of the numbers backwards (i.e., 40, 39, ..., 0), takes a few minutes more. About an hour ago I set the computer to task on a 100,000 element array of unique numbers that had been randomly mixed up, and it is still going.
sub bbl_sort { my $array = shift; my $not_complete = 1; my $index; my $len = ((scalar @$array) - 2); while ($not_complete) { $not_complete = 0; foreach $index (0 .. $len) { if (@$array[$index] > @$array[$index + 1]) { my $temp = @$array[$index + 1]; @$array[$index + 1] = @$array[$index]; @$array[$index] = $temp; $not_complete = 1; } } } }
In reply to Simple bubble sort by IndyZ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |