Thank you , but I still have something to understand.
Have a look on your post on lines 7,8,9,10,11
1 2 3 4
|
root.printValue(); // print Y
inorderTraversal(P);
inorderTraversal(NULL); // abort node since NULL
root.printValue(); // print P
|
and have a look on the function also
1 2 3 4 5 6 7
|
void inorderTraversal( Node root )
{
if( root == null ) return;
(1) inorderTraversal( root.getLeft() );
(2) root.printValue();
(3) inorderTraversal( root.getRight() );
}
|
after printing 'Y' by calling root.printValue(); , the function continues to the next statement inorderTraversal( root.getRight() ); , and calls P , so we have now inorderTraversal(P);
what now?? P has no leafs , both are NULL. Do we now call the NULL on the left leave of P or NULL on the right leave??
Let me say that in different way :-), when we arrive to P, so we are on statement number (3) , since it is on right, then we stay call on statement (3) , inorderTraversal(p->right), which is inorderTraversal(NULL) - Go back - call is terminated .... the questions where we go back now ? is it to statement (1), and call inorderTraversal(p-->left) , which is inorderTraversal(NULL), and then print P??
Thank you