You are viewing a single comment's thread. Return to all comments →
i dont understand how you are adding nodes if root.left or root.right are NULL.
heres my solution in cpp can anyone please explain me how to do this without checking the null condition in left or right.
Node * insert(Node * root, int data) { if(!root) return new Node(data); if(data < root->data){ if(root->left) insert(root->left,data); else root->left = new Node(data); } else if(data > root->data){ if(root->right) insert(root->right,data); else root->right = new Node(data); } return root; }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all comments →
i dont understand how you are adding nodes if root.left or root.right are NULL.
heres my solution in cpp can anyone please explain me how to do this without checking the null condition in left or right.