Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4cf6df8

Browse files
add transplant method
1 parent 5b9365e commit 4cf6df8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎data-structures/binary-search-tree.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ BST.prototype.delete = function (value) {
3535
// or in the Tree object?
3636
}
3737

38+
BST.prototype.transplant = function (u, v) {
39+
if (!u.parent)
40+
this.root = v
41+
else if (u === u.parent.left)
42+
u.parent.left = v
43+
else
44+
u.parent.right = v
45+
if (v) {
46+
v.parent = u.parent
47+
}
48+
}
49+
3850
BST.prototype.search = function (value) {
3951
let current = this.root
4052
while (current) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /