I wrote the following code but it doesn't work for nodes except the root node.
public Node deleteSubTree(Node root) {
if(root == null) {
return null;
}
root.left = deleteSubTree(root.left);
root.right = deleteSubTree(root.right);
//System.out.print(" : deleting-"+root.data);
root = null;
return root;
}
I am passing the node to be deleted as the argument. Could you please tell what is wrong with this code?