Fix broken balance method

This commit is contained in:
Manuel Thalmann 2022-10-31 20:50:09 +01:00
parent 24225d7595
commit 479cac0393

View file

@ -43,18 +43,18 @@ public class AVLSearchTree<T extends Comparable<T>> extends SortedBinaryTree<T>
} else if (height(p.left) - height(p.right) == 2) {
if (height(p.left.left) >= height(p.left.right)) {
// TODO Implement (6.2)
rotateR(p);
p = rotateR(p);
} else {
// TODO Implement (6.2)
rotateLR(p);
p = rotateLR(p);
}
} else if (height(p.right) - height(p.left) == 2) {
if (height(p.right.right) >= height(p.right.left)) {
// TODO Implement (6.2)
rotateL(p);
p = rotateL(p);
} else {
// TODO Implement (6.2)
rotateRL(p);
p = rotateRL(p);
}
}
p.height = Math.max(height(p.left), height(p.right)) + 1;