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 f8d360a

Browse files
committed
bug fix in delete node
1 parent 3f69eba commit f8d360a

File tree

1 file changed

+4
-6
lines changed
  • tuts/data-structures/binary-search-tree

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ const deleteNode = (root, value) => {
2828
} else if (value > root.value) {
2929
root.right = deleteNode(root.right, value);
3030
} else {
31-
if (root.left === null && root.right === null) {
32-
return null;
33-
} else if (root.left === null && root.right) {
31+
if (root.left === null) {
3432
return root.right;
35-
} else if (root.right === null&&root.left) {
33+
} else if (root.right === null) {
3634
return root.left;
3735
} else {
3836
let nextHighestNode = root.right;
39-
while (nextHighestNode&&nextHighestNode.left) {
37+
while (nextHighestNode.left) {
4038
nextHighestNode = nextHighestNode.left;
4139
}
4240
root.value = nextHighestNode.value;
43-
root.right = deleteNode(nextHighestNode, nextHighestNode.value);
41+
root.right = deleteNode(root.right, nextHighestNode.value);
4442
}
4543
}
4644

0 commit comments

Comments
(0)

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