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

Re: Binary Search Tree Debug Question

by FunkyMonk (Canon)
on Aug 13, 2011 at 13:56 UTC ( #920171=note: print w/ replies, xml ) Need Help??

in reply to Binary Search Tree Debug Question

if ( $tree->{VALUE} > $value ) { insert( $tree->{LEFT}, $value ) } elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value )
What if the data includes duplicated values? The Perl CookBook (1st and 2nd editions) had an additional line:
if ( $tree->{VALUE} > $value ) { insert( $tree->{LEFT}, $value ) } elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value ) else { warn "$value duplicated" }

or, if you want to include the duplicates, change either '>' to '>=', or '<' to '<=':

if ( $tree->{VALUE} >= $value ) { insert( $tree->{LEFT}, $value ) } elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value )

Comment on Re: Binary Search Tree Debug Question
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://920171]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2015-11-30 02:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (756 votes), past polls