Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: How do I create a binary tree ?by punitpawar (Sexton) |
on Dec 06, 2015 at 19:20 UTC ( [id://1149530]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|