File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -316,4 +316,41 @@ int main() {
316316 bst.createSampleTree1 ();
317317 bst.prettyPrint ();
318318 return 0 ;
319- }
319+ }
320+
321+ // // replace the subtree rooted at node u with the subtree
322+ // // rooted at node v.
323+ // void transplant(NodePtr u, NodePtr v){
324+ // if (u->parent == nullptr) {
325+ // root = v;
326+ // } else if (u == u->parent->left) {
327+ // u->parent->left = v;
328+ // } else{
329+ // u->parent->right = v;
330+ // }
331+
332+ // if (v != nullptr) {
333+ // v->parent = u->parent;
334+ // }
335+ // }
336+
337+ // // delete node x
338+ // void deleteNodeHelper(NodePtr x, int key) {
339+ // if (x->left == nullptr) {
340+ // transplant(x, x->right);
341+ // } else if (x->right == nullptr) {
342+ // transplant(x, x->left);
343+ // } else {
344+ // y = minimum(x->right);
345+ // if (y->parent != x) {
346+ // transplant(y, y->right);
347+ // y->right = x->right;
348+ // y->right->parent = y;
349+ // }
350+ // transplant(x, y);
351+ // y->left = x->left;
352+ // y->left->parent = y;
353+ // }
354+
355+ // // fix the tree after the deletion
356+ // }
You can’t perform that action at this time.
0 commit comments