Why segmentation fault
i didnt understand that…whats “pre” ?
also why do we need to take s==e separately when i have put a condition only on s>e…so s<=e should already take for s==e.
errors
for(int i=0;i<a;i++){
cin>>arr1[a];
}
int b;
cin>>b;
int arr2[b];
for(int i=0;i<b;i++){
cin>>arr2[b];
}
these should be arr[i]
it is array containing preorder traversal in your case it is arr1
because this is leave node no need to call left or right
yes you have to take it seprately
because for ex
s=0 e=0
means you are at node with data 3
now you call for left part
root->left=build(arr1,arr2,s,php-1);
which is root->left=build(arr1,arr2,0,-1);
when you access arr[-1] it will give segmentaion fault that’s why you have to take this condition seprately
modified code
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.