note
FunkyMonk
<blockquote><i>
<code>
if ( $tree->{VALUE} > $value ) { insert( $tree->{LEFT}, $value ) }
elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value )
</code>
</i></blockquote>
What if the data includes duplicated values? The Perl CookBook (1<sup>st</sup> and 2<sup>nd</sup> editions) had an additional line:
<code>
if ( $tree->{VALUE} > $value ) { insert( $tree->{LEFT}, $value ) }
elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value )
else { warn "$value duplicated" }
</code><p>
or, if you want to include the duplicates, change either '<c>></c>' to '<c>>=</c>', or '<c><</c>' to '<c><=</c>':<P>
<code>
if ( $tree->{VALUE} >= $value ) { insert( $tree->{LEFT}, $value ) }
elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value )
</code><p>
<div class="pmsig"><div class="pmsig-611550">
<hr><small>
<br><b>Perl</b>:
[doc://perlintro]
[doc://perlretut]
[id://745674] <!-- Basic debugging checklist -->
<br><b>PerlMonks</b>:
[id://174051] <!-- Writeup Formatting Tips -->
[id://674668] <!-- Markup in the Monastery -->
[id://174051] <!-- How do I post a question effectively? -->
[id://510718] <!-- I know what I mean. Why don't you? -->
<br><b>General</b>:
[http://catb.org/~esr/faqs/smart-questions.html|How To Ask Questions The Smart Way]
[http://docs.sun.com/source/806-3568/ncg_goldberg.html|What every computer scientist should know about floating-point arithmetic]
<br>
To Be Continued...
</small>
</div></div>
920057
920057