How do can I create binary trees in Perl?
5 Answers
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.
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.
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
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".
-
err, seems more like maybe your not updating your code to match the API has made the system crash :)– ysthCommented Jul 9, 2013 at 22:35
-
1I 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. Commented Jul 9, 2013 at 22:41