Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by blakem (Monsignor)
on Apr 06, 2003 at 03:12 UTC ( [id://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 Heap.pm 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.

-Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-19 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found