-3

How do can I create binary trees in Perl?

1
  • What have you tried so far and where are you running into trouble? Have you ever programmed a binary tree in another language? Commented Sep 29, 2009 at 23:17

5 Answers 5

7

CPAN contains a very wide variety of different modules, and rather than reinventing the wheel, I would suggest looking for it there first. Tree::Binary seems to do what you want to do.

5

I'm guessing this is some kind of homework assignment (although it's hard to tell from the question), so if you actually have to write your own, a good place to start would be learning how to create objects in Perl (here's a tutorial). The wikipedia page will probably be helpful as well.

A more detailed question will yield better responses.

5

There's the Tree::Binary module in CPAN...

3

Although I haven't used it, Tree::RedBlack creates the tree and keeps it balanced (if doing deletes or insertions). If I recall, some of the other tree modules may not provide this capacity (if I have it right).

Chris

1

I would avoid Tree::Binary from CPAN. We have production software that depends on it, and its API has changed significantly twice in the past two years, making the system crash. For instance, there is a function that continues to do the same thing, but the authors saw fit to at first call it "set_left", then change it to "left", and now "setLeft".

2
  • err, seems more like maybe your not updating your code to match the API has made the system crash :)
    – ysth
    Commented Jul 9, 2013 at 22:35
  • 1
    I maintain a system that uses hundreds of third-party modules and programs. If I had to update my code for each one once a year, I wouldn't have time to do anything else.
    – Phil Goetz
    Commented Jul 9, 2013 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.