On May 12, Andrew Gaffney said:

>> This sounds like postorder tree traversal to me:
>
>I've seen that term before when looking into this, but I don't know what
>it means.

I'd suggest bookmarking the wikipedia, it has a lot of encyclopedia-style
definitions (read, long texts and examples) of computer terminology:

  http://en.wikipedia.org/wiki/Pre-order_traversal

is a page about binary trees and talks about pre-, in-, and post-order
traversal.

(Wikipedia.org is not strictly computer stuff, but it's got a boat-load of
computer stuff.)

See also the Free On-Line Dictionary of Computing (FOLDOC) -- it's often
less verbose (or more terse, depending on what vocabulary you like to use)
but it's helpful nonetheless:

  http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?traversal

>>   postorder(\%tree, 'package1');
>>
>>   sub postorder {
>>     my ($tree, $pkg, $seen) = @_;
>>     return if $seen->{$pkg}++;  # to stop from traversing a node twice
>>
>>     postorder($tree, $_, $seen) for @{ $tree->{$pkg} };
>>     print "$pkg\n";
>>   }
>
>Is $seen another hash that should be passed as a reference to postorder() ?

You don't need to send it in your outermost call to it.  That's the
beauty of Perl.  The first time the function is called (assuming you DON'T
pass it a third argument) $seen is undef.  When we say $seen->{$pkg}++,
Perl automatically makes $seen a hash reference.  Then, for all the
recursive calls in the function itself, you see that we DO pass $seen.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to