Doubt in the answer

please comment the errors

@Adhyayan,
https://ide.codingblocks.com/s/228472 corrected code.

Errors:

  1. a lot of cases were missing in the deletenode function when n1.left!=null &&n1.right==null and n1.left == null && n1.right != null.
  2. max function will be modified.

If the right child is not empty you need to find the inorder successor. What you are doing is correct, we can also replace it with inorder predecessor (max element on the left child node) but, the important thing to note is, inorder predecessor is needed only when right child is empty.

Also, your construction method was wrong.

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.