Tried to implement a method to remove a vertex from a binary tree. The problem is that when I want to remove the root of the tree it is not deleted, tell me where the error is.
private static Node delete(Node n, int x) { if(n == null) return n; if (x > nx) nr = delete(nr, x); else if (x < nx) nl = delete(nl, x); else if (nr != null && nl != null) { nx = nrminimum().x; nr = delete(nr, nrx); } else { if (nr != null) n = nr; else n = nl; } return n; } public void remove(int x){ delete(this, x); } 

Node.removeis useless in this form. Suppose you only have a root vertex with a value of 5, you callкорень.remove(5), the method callsdelete(this, 5), which honestly returnsnull(корень.l), which is not used at all. You can create a classTree, which will have arootfield, and a methodremove(int x) { root = delete(root, x); }remove(int x) { root = delete(root, x); }. - zRrr