how recursion works in the insert function and return root?
Not understand borh functions insert and print
node*buildTree(){
int d;
cin>>d;
if(d==-1){
return null;
}
root=new node(d);
root->left=buildTree(root->left);
root->right=buildTree(root->right);
return root;
}
first we take input d and make its node
then we construct it’s left subtree
then we construct it’s right subtree
now return the root node
this will work for each node and build the tree
for detailed explanation watch the video again
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.