WHY NOT PASSING ROOT BY REFERENCE

in this question we are changing either the left or right pointer inside the root node so why are we not passing it by reference as node*& root as we did in linked list when the next pointer of head node is changing.

according to me the code taught in this video will not work for the case when a node has 1 child as in that case we are deleting the the required node and making our previous node point to the next node.

@Parmeet-Kalsi-1631789033630118 we dont need to pass it by reference if we are returning the new node and assiging it…you can do a dry run if you are unsure. Passing by reference is not the only way to change the values of the variables.

thanks a lot for that…

1 Like