Why the code isn’t working .
It’s giving correct answer for sample test case.
Delete Node from BST
logic for deleting node is correct
but the logic to build bst you have used is not mention in question so
you have to use normal method to build bst
like this
node* insertnode(int d, node*startnode) {
if (startnode == NULL) {
node*nn = new node(d);
return nn;
}
if (startnode->data > d) {
startnode->left = insertnode(d, startnode->left);
}
else {
startnode->right = insertnode(d, startnode->right);
}
return startnode;
}
void BuildTree(int *arr, int n) {
for (int i = 0; i < n; i++) {
rootnode = insertnode(arr[i], rootnode);
}
}
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask