Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Golf: Tree searching

by koolade (Pilgrim)
on Apr 19, 2001 at 23:01 UTC ( #73933=note: print w/replies, xml ) Need Help??

in reply to Golf: Tree searching

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?

Here's what I'm using to test:

$t = { d => 'd', l => { d => 'b', l => { d => 'a', l => 0, r => 0, }, r => { d => 'c', l => 0, r => 0, }, }, r => { d => 'f', l => { d => 'e', l => 0, r => 0, }, r => { d => 'g', l => 0, r => 0, }, } };

And here's a solution in 92 chars, that puts the tree into a single hash, and searches using the hash:

sub f{r(pop);$a{(pop)}||0;sub r{my$n=shift||return;$a{$n->{d}}=$n;r($n +->{l});r($n->{r});};};

Speak up if I missed something.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://73933]
[enrgyxprt]: how do I delete a question
[Lotus1]: you can't but you can request to have it deleted.
[Lotus1]: you can edit it as long as you were logged in when you submitted it

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2017-01-17 13:19 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (156 votes). Check out past polls.