On Thu, Jul 26, 2001 at 03:06:38AM -0700, Abigail wrote:
> We all remember our fundamental algorithms, don't we?

Not really, which is why it's good to have you remind us :-)
Now that you mention it, though,

> sub heapify ($$$$) {
>     my ($code, $index, $array, $bound) = @_;
>     {
>         my $child = 2 * $index;

that heap looks a bit funny.  I think you meant

          my $child = 2 * $index + 1;

(The original works, by chance.)

Andrew

>         my $max = $index;
>         foreach my $offset (0 .. 1) {
>             my $child = $child + $offset;
>             $max = $child if do {local ($a => $b) = @$array [$max => $child];
>                                  $child < $bound && &$code < 0};
>         }
>         return if $max == $index;
>         @$array [$index => $max] = @$array [$max => $index];
>         $index = $max;
>         redo;
>     }
> }

Reply via email to