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?


currentseems to be a local variable. If you pushcurrentinto yourStackit will contain the reference tocurrent. But ascurrentis also a variable you´re changing the referencecurrentis refering to. But that wont magically chence the reference you did push into theStack. Check this SO question for further details