Here’s my code :
Runtime error i code
@Akankshaq,
Don’t sort the array before construction. Preserve the order of the elements.
private Node construct(int item, Node node) {
if (node == null) {
Node nn = new Node();
nn.data = item;
return nn;
}
if (item < node.data) {
node.left = construct(item, node.left);
}
if (item > node.data) {
node.right = construct(item, node.right);
}
return node;
}
Pass arr[i] and root and it will recursively place the element at the right node. Also, add testcases to delete function in case the parent is null.