is this code correct for making a skewed tree?
node *skewedtree(int arr[],int n){
node *root=NULL;
node *temp=new node(arr[0]);
root=temp;
for(int i=1;i<n;i++){
temp=temp->left;
temp=new node(arr[i]);
}
return root;
}
is this code correct for making a skewed tree?
node *skewedtree(int arr[],int n){
node *root=NULL;
node *temp=new node(arr[0]);
root=temp;
for(int i=1;i<n;i++){
temp=temp->left;
temp=new node(arr[i]);
}
return root;
}
Hey @Rj.25 i think there is an error in FOR loop.
for(int i=1;i<n;i++){
temp=temp->left;
temp=new node(arr[i]);
}
should be updated to
for(int i=1;i<n;i++){
temp->left= new node(arr[i]);
temp = temp->left;
}
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.