HI Laurent,
Thanks for the response. The part which I do not understand is , how are the nodes inserted after a second node has been created.
So say for instance the first node is with value 40. So this node now contains undefined references to the Left and Right node.
Now say the second value that is generated is 60 , This is inserted to the Right of the tree. So $tree->{right} points a new tree with value 60.

( I understand till here) But now say if third value that is generated is 80 . At this point in time $root still points to the orignal tree with value 40.
Now because $root is already defined it skips to the if else condition , and makes a call that 80 > 40 , hence it should be inserted to the right
But $tree->{Right} is already defined , and it contains the value 60, so it never executes the actual routine to create a reference to a new tree .....


So I am confused about the way they are using references to move things around.....

And what if the third value that is generated is 50 . 50 >40 hence it will be inserted at the right. But 50<60 , so it should be inserted to the left of 60 in its tree.
How is this determined in the code ?
Will appreciate any help you can provide to clear my understanding....

In reply to Re^2: How do I create a binary tree ? by punitpawar
in thread How do I create a binary tree ? by punitpawar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.