<?xml version="1.0" encoding="windows-1252"?>
<node id="73933" title="Re: Golf: Tree searching" created="2001-04-19 19:01:26" updated="2005-07-19 14:08:39">
<type id="11">
note</type>
<author id="70453">
koolade</author>
<data>
<field name="doctext">
&lt;p&gt;I haven't been able to get some of the answers to work.  Maybe I have a different image of the data structure.  Can somebody post what they've been working with?

&lt;p&gt;Here's what I'm using to test:

&lt;code&gt;
$t = {
    d =&gt; 'd',
    l =&gt; {
        d =&gt; 'b',
        l =&gt; { d =&gt; 'a', l =&gt; 0, r =&gt; 0, },
        r =&gt; { d =&gt; 'c', l =&gt; 0, r =&gt; 0, },
    },
    r =&gt; {
        d =&gt; 'f',
        l =&gt; { d =&gt; 'e', l =&gt; 0, r =&gt; 0, },
        r =&gt; { d =&gt; 'g', l =&gt; 0, r =&gt; 0, },
    }
};
&lt;/code&gt;

&lt;p&gt;And here's a solution in 92 chars, that puts the tree into a single hash, and searches using the hash:

&lt;code&gt;
sub f{r(pop);$a{(pop)}||0;sub r{my$n=shift||return;$a{$n-&gt;{d}}=$n;r($n-&gt;{l});r($n-&gt;{r});};};
&lt;/code&gt;

&lt;p&gt;Speak up if I missed something.</field>
<field name="root_node">
73900</field>
<field name="parent_node">
73900</field>
</data>
</node>
