Skip to content

Commit

Permalink
fix: bug in AVL tree delete
Browse files Browse the repository at this point in the history
  • Loading branch information
4ndrelim committed Apr 29, 2024
1 parent 37c99e3 commit 19dabf2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/dataStructures/avlTree/AVLTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private Node<T> delete(Node<T> node, T key) {
node.setLeft(delete(node.getLeft(), key));
} else {
if (node.getLeft() == null || node.getRight() == null) { // case of 1 or 0 child
// node = node.left == null ? node.right : node.left;
if (node.getLeft() == null && node.getRight() == null) {
node = null; // 0-child case
} else if (node.getRight() == null) {
Expand All @@ -245,10 +244,10 @@ private Node<T> delete(Node<T> node, T key) {
}
}

if (node != null) { // make sure it isnt the 0-child case
rebalance(node);
if (node != null) { // make sure it isn't the 0-child case
return rebalance(node);
}
return node;
return node; // null; case when nothing left
}

/**
Expand Down

0 comments on commit 19dabf2

Please sign in to comment.