Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Heap sorting in perl

by Ovid (Cardinal)
on Apr 05, 2003 at 15:08 UTC ( #248297=note: print w/ replies, xml ) Need Help??


in reply to Heap sorting in perl

Can you give some examples where it's having problems? Perhaps we can figure out what's going on. To be fair, I haven't used Heap.pm, but I did notice that it's tests are not terribly comprehensive, so I'm not surprised. I confess a desire to see what's not working and start writing tests for it :)

If you happen to have a copy of "Mastering Algorithms with Perl", by O'Reilly, they have a heap implementation in there along with an excellent discussion. Perhaps rolling your own my help?

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)


Comment on Re: Heap sorting in perl
Re: Re: Heap sorting in perl
by Anonymous Monk on Apr 05, 2003 at 15:42 UTC
    I just attempted to download and install Heap. Its example broke for me upon attempting call add. (Not autoloaded.) Perl 5.6.1 on Linux here.

    Is anyone maintaining it? Is it worthwhile to file a bug report?

      I got the same error with Perl 5.8 on Linux. After a quick search turned up mixed reviews for the module, I decided to post here before making my next move. At the very least, I'll email the author of Heap with a bug report.

      -Blake

Got Heap.pm to work... (was Re2: Heap sorting in perl)
by blakem (Monsignor) on Apr 06, 2003 at 03:12 UTC
    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
Node Status?
node history
Node Type: note [id://248297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-12-22 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (109 votes), past polls