pranav shukla pranav shukla - 1 month ago 5
Java Question

Reference to Classes in Java

I was doing inorder traversals when in the solution I came across the following lines:

stack.push(current);
current = current.left;


Now my question is that when I push current into the stack and make
current = current.left;
then will the node that is there within the
stack
also change to
current.left
? In my case, the current in the
stack
still points to the original
current
but the
current
variable does point to
current.left
. Why is this?

Answer
stack.push(current);

enter image description here

current = current.left;

enter image description here