so the tree should look like this:$q = new Tree; $q->addnode(4); $q->addnode(3); $q->addnode(5); $q->addnode(14); $q->addnode(15); $q->addnode(7); $q->addnode(19); $q->display;
So i'd expect the display routine to list the numbers in order, starting with the lowest. In fact, what I get is:4 / \ 3 5 \ 14 /\ 7 15 \ 19
What seems to be happening is that it correctly finds it's starting point, at which point there are 2 levels of recursion. It prints the node value, then goes back to the calling level, but still refers to the lowest level node. So print $head->{Val}, "\n"; still, for some reason prints '3'. Incidentally, if i run it from right to left, i get3 3
Do you see what i mean? When a subroutine ends and passes control back up to the calling level, is $head not being returned to it's value in the calling routine?19 19 19 19 19
In reply to Re: recursion
by Basilides
in thread Trouble traversing binary tree (was: recursion)
by Basilides
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |