my question relates to the main function why do I have to set passIn = to tree.addNode(passIn,1) for this code to work
why can't I just say
tree.addNode returns a newNode in the first case,when we pass in the Node pointer passIn we are passing by reference since pointers are passed by reference so how come we don't have to say passIn = tree.addNode(passIn,3); and for subsequent values?
why do we have to to do this the first time around?
for example when I change passIn = tree.addNode(passIn,1) to tree.adNode(passIn,1) 7 is found does not display in the console
Sorry for my English...
First of all, what is the reason to have a Tree class? It doesn't have any fields to hold values and all methods are public. But okay... Let's go to your question.
we are passing by reference since pointers are passed by reference
Emm... You can pass object by value, by pointer or by reference, it's right. And in your example you're passing object by pointer. But pointer as it is passing by value. So you can change it inside function but it won't change outside. Btw if you change object that pointed by it of course it will change.
Also if it wouldn't be so... addNode method doesn't change value of tree at all - it only add a pointer to a new Node to apropriate current node.
So your passIn remains NULL until you set it by returned pointer.