Delete node from BST problem

I am getting segmentation fault, for the part of code, where i’ve written logic to delete the node with 1 or 2 children. Help me with this.

hey anurag there was a bit mistake in your code. I have corrected some lines please check it here.
https://ide.codingblocks.com/s/613942.

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.

hey, only 1 test case passed, for rest, it is showing Run Error

hey anurag please check out this code https://ide.codingblocks.com/s/616145
your code have a bit mistake in it which i resolved earlier.

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.

Hey, why have you used else statement at line 83. What does it signify?


there must be 3 cases

  1. data < root->data
  2. data == root->data
  3. data > root->data;

so else part is considering the 3rd case

what’s wrong in this?

if you didn’t use else then line 85 and 86 executed for each other case which is wrong

hope you got my point
if not feel free to ask

hey, yeah i understood. But still i am unable to get why my code is not right. Please help me with that. 4 out of 5 test cases are showing run error.

at line no 133 in main()

this is correct statement
root = deleteFromBST(root,a2,m);

because after deletion root node may change
you have to update the root in main()

hey, after updating as you said, 4 out of 5 test cases are still showing run error

you have also missed
if(root == NULL)
return root;

Modified Code