Code not working what is mistake?

Code not working for test cases its working fine on sample case.

Hey , i can’t see your code.It looks like you haven’t saved it.


Btw,you can read about deletion from here.It is explained in detail.

#include<bits/stdc++.h> using namespace std; class node{ public : int data; node* left; node* right; node(int data){ this -> data = data; left = NULL; right = NULL; } }; node* buildTreeFromArray(int* a, int s, int e){ if(s > e){ return NULL; } int mid = (s+e)/2; node* root = new node(a[mid]); root -> left = buildTreeFromArray(a, s, mid-1); root -> right = buildTreeFromArray(a, mid+1, e); return root; } void print(node* root){ if(root == NULL){ return; } cout << root -> data << " "; print(root -> left); print(root -> right); } node* deletionInBST(node* root, int key){ if(root == NULL){ return root; } if(key < root -> data){ root -> left = deletionInBST(root -> left, key); return root; } else if(key > root -> data){ root -> right = deletionInBST(root -> right, key); return root; } else{ if(root -> left == NULL && root -> right == NULL){ delete(root); return NULL; } else if(root -> left && root -> right == NULL){ node* temp = root -> left; delete(root); return temp; } else if(root -> right && root -> left == NULL){ node* temp = root -> right; delete(root); return temp; } else{ node* temp = root -> right; while(temp -> left != NULL){ temp = temp -> left; } root -> data = temp -> data; root -> right = deletionInBST(root -> right, temp -> data); return root; } } } int main(){ int tc; cin >> tc; while(tc–){ int n; cin >> n; int* a = new int[n]; for(int i=0; i<n; i++){ cin >> a[i]; } sort(a,a+n); node* root = buildTreeFromArray(a,0,n-1); int k; cin >> k; while(k–){ int d; cin >> d; deletionInBST(root, d); } print(root); cout << endl; } }

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.