Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Got to work... (was Re2: Heap sorting in perl)

by blakem (Monsignor)
on Apr 06, 2003 at 03:12 UTC ( #248384=note: print w/ replies, xml ) Need Help??

in reply to Re: Heap sorting in perl
in thread Heap sorting in perl

Thanks for the book tip... After skimming through the "Mastering Algorithms" section on heaps and reading through the source, I was able to build a small script that seems to work:

#!/usr/bin/perl -wT use strict; use Heap::Binary; use Heap::Elem::Num; my $heap = Heap::Binary->new; for (25,33,107,5,42,29) { my $elem = Heap::Elem::Num->new($_); $heap->add( $elem ); } my $min = $heap->extract_minimum(); print "Min: " . $min->val . "\n"; # prints 5
Unfortunately this doesn't exactly match the usage explained in the POD. It could be just a documentation bug, but it worries me a bit.


Comment on Got to work... (was Re2: Heap sorting in perl)
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://248384]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2015-11-28 09:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls