ok, i add some nodes (the addnode routine works, i know), and then call display:
$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 the tree should look like this:
4
/ \
3 5
\
14
/\
7 15
\
19
So i'd expect the display routine to list the numbers in order, starting with the lowest. In fact, what I get is:
3
3
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 get
19
19
19
19
19
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?