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; } } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 1: Simple bubble sort
by tilly (Archbishop) on Sep 20, 2001 at 07:43 UTC | |
by Anonymous Monk on Nov 12, 2014 at 19:19 UTC | |
Re: Simple bubble sort
by clintp (Curate) on Sep 20, 2001 at 05:45 UTC | |
by blakem (Monsignor) on Sep 20, 2001 at 09:22 UTC | |
Re: Simple bubble sort
by Zaxo (Archbishop) on Sep 19, 2001 at 09:55 UTC | |
Re: Simple bubble sort
by lemming (Priest) on Sep 19, 2001 at 09:36 UTC | |
by IndyZ (Friar) on Sep 19, 2001 at 23:50 UTC |