### Binary Search Tree Delete Node()

My grader said that my delete function doesn't even work. I've ran it myself and debugged prior to turning it in and from what I could see it did work. Wondering if there was something that I missed or fat-fingered? Advice would be appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138`` ``````void BST::BST_Erase(int item) { // Call Erase Recursive Function BST_Erase(root, item); } // Pre-Con: Root and item passed as parameters // Post-Con: Item is deleted from the tree void BST::BST_Erase(Node* n, int item) { // Find the item bool found = false; Node* predecessor=nullptr; Node* current=n; if(current==nullptr) cout<<"Tree is empty"<data==item) { found = true; break; } else { predecessor = current; if(item > (current->data)) current=current->right; else current=current->left; } } if(!found) { cout<left==nullptr && current->right != nullptr) || (current->left != nullptr && current->right==nullptr)) { // Right Leaf Present, No Left Leaf if(current->left==nullptr && current->right != nullptr) { // If predecessor's left tree equals Node n if(predecessor->left==current) { // then predecessor's left tree becomes n's right tree // and delete n predecessor->left=current->right; delete current; current=nullptr; cout<right=current->right; delete current; current=nullptr; cout<left==current) { predecessor->left=current->left; delete current; current=nullptr; cout<right=current->left; delete current; current=nullptr; cout<left==nullptr && current->right==nullptr) { if(predecessor->left==current) predecessor->left=nullptr; else predecessor->right=nullptr; delete current; cout<left != nullptr && current->right != nullptr) { Node* check=current->right; if((current->left==nullptr)&&(current->right==nullptr)) { current=check; delete check; current->right==nullptr; cout<right)->left!=nullptr) { Node* leftCurrent; Node* leftCurrentPred; leftCurrentPred=current->right; leftCurrent=(current->right)->left; while(leftCurrent->left != nullptr) { leftCurrentPred=leftCurrent; leftCurrent=leftCurrent->left; } current->data=leftCurrent->data; delete leftCurrent; leftCurrentPred->left==nullptr; cout<right; current->data=temp->data; current->right=temp->right; delete temp; cout<
Please mention the error that you get.
Apparently my delete function isn't removing the specified node from the tree. I just double checked it and it doesn't work, which I find odd cause I could have sworn that it worked prior to submitting.
I got it fixed. My problem was line 16`cout<<"Tree is empty"<<endl;return`. I needed the return on the next line.
Topic archived. No new replies allowed.