Skip to content

Commit a8db294

Browse files
committed
Treap added
1 parent 3fd9517 commit a8db294

3 files changed

Lines changed: 454 additions & 1 deletion

File tree

data-structures/binary-search-trees/BST.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
// }

0 commit comments

Comments
 (0)