BradThePerlNeophyte has asked for the wisdom of the Perl Monks concerning the following question:
# get total number of data lines entered # by using the "date" array $totalentries = $#date; # move it up one to make the count accurate $totalentries = $totalentries + 1; # Bubble Sort Data # set a Flag $flag = 1; until ($flag == 0) { $n = 0; $counter = $totalentries; $flag = 0; # the flag is changed from 1 to 0. # Not sure if the "until" function will drop out # at this point or not. Don't know a better way. . . while ($counter > 0) { $n2 = $n + 1; if (int $date[$n] < int $date[$n2]) { # if this is true, perform the swap of # the same elements in each array $placeholder = $date[$n]; $date[$n] = $date[$n2]; $date[$n2] = $placeholder; $placeholder = $provider[$n]; $provider[$n] = $provider [$n2]; $provider[$n2] = $placeholder; $placeholder = $description[$n]; $description[$n] = $description[$n2]; $description[$n2] = $placeholder; $placeholder = $exhibit[$n]; $exhibit[$n] = $exhibit[$n2]; $exhibit[$n2] = $placeholder; $placeholder = $page[$n]; $page[$n] = $page[$n2]; $page[$n2] = $placeholder; # if a change occurred, change the flag to "1" $flag = 1; } ++$n; --$counter; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: bubble sort problems
by arturo (Vicar) on Jul 12, 2001 at 19:27 UTC | |
|
Re: bubble sort problems
by Masem (Monsignor) on Jul 12, 2001 at 19:29 UTC | |
|
Re: bubble sort problems
by VSarkiss (Monsignor) on Jul 12, 2001 at 19:30 UTC | |
|
swapping elements efficiently (boo)
by boo_radley (Parson) on Jul 12, 2001 at 20:17 UTC | |
by bikeNomad (Priest) on Jul 12, 2001 at 20:23 UTC | |
by boo_radley (Parson) on Jul 12, 2001 at 20:31 UTC |