BST to linked list

Hi i was going through the vid in which we convert a BST to linked list and i want to know while attaching the left subtree to root node, why we do tailLeft.tail->right = root. why is ‘right’ written here and not tailLeft.tail = root. What does ‘right’ here signifies?

hello @vanya.garg

leftLinkedList = flatten(root->left) // it will flatten the left sutree
rightLInedlist=flatten(root->right) // it will flatten the right subtree

now what exactly we want to do.
we first want to connect root node at the end of tail of leftlinkedlist right?

how we can do that ? first we need to find the tail node of left list
(leftLinkedList.tail will give us the tail node of left linked linked list)
and then we need to append root to the right of this node. so for that we do
leftLinkedList.tail-> right=root ;

in short
(tail node of left list) -> right = root;

check the node class we have left and right pointer in it.
so right signfies the pointer only

ss
use this for visualization

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.