can u correct my code? i think im somewhere near to the answer, my approach is to go post order and also maintain one sum value that will be added each time when the function call goes back.
Replace with sum of greater nodes
Sanchit, plz change your replaceSum function, use the following code instead…
void BSTsum(node *root)
{
int sum=0;
modifysum(root,&sum);
}
Modifysum function will be an additional function such that it would have ,
if(root==NULL)
{
return;
}
modifysum(root->right,sum);
*sum=*sum+root->data;
root->data=*sum;
modifysum(root->left,sum);
Work as per this logic, rest code is correct…
but what was wrong in my code
???
The value of sum was not getting updated correctly in your code…thts why your approach was wrong.