DreamT has asked for the wisdom of the Perl Monks concerning the following question:

So, I have an object of objects, representing a binary tree with n levels. All of them have an unique ID (which can be random), and a Level and position. In other words, every object have a "left" and a "right" object, and for each level the number of objects are doubled.
The "position" parameter indicates the objects "left-to-right" position in the current level. I'd like to print the tree using "Breadth-first search", i.e. i want to iterate over level and position so that the following (only showing the "position")
1 12 1234
prints in the following order:
1 23 4567


How can I do it?

Replies are listed 'Best First'.
Re: Object of objects, Binary tree,
by ikegami (Patriarch) on Mar 04, 2011 at 17:49 UTC
    my @todo = $tree; while (@todo) { my $node = shift(@todo); ... push @todo, $node->children; }
Re: Object of objects, Binary tree,
by Anonymous Monk on Mar 04, 2011 at 16:05 UTC