Implement AVLSearchTree
This commit is contained in:
parent
1f5b475645
commit
d04f74f992
1 changed files with 5 additions and 1 deletions
|
@ -19,7 +19,7 @@ public class AVLSearchTree<T extends Comparable<T>> extends SortedBinaryTree<T>
|
||||||
@Override
|
@Override
|
||||||
protected int calcSize(TreeNode<T> p) {
|
protected int calcSize(TreeNode<T> p) {
|
||||||
// TODO Implement (6.2)
|
// TODO Implement (6.2)
|
||||||
throw new RuntimeException();
|
return super.calcSize(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,14 +43,18 @@ public class AVLSearchTree<T extends Comparable<T>> extends SortedBinaryTree<T>
|
||||||
} else if (height(p.left) - height(p.right) == 2) {
|
} else if (height(p.left) - height(p.right) == 2) {
|
||||||
if (height(p.left.left) >= height(p.left.right)) {
|
if (height(p.left.left) >= height(p.left.right)) {
|
||||||
// TODO Implement (6.2)
|
// TODO Implement (6.2)
|
||||||
|
rotateR(p);
|
||||||
} else {
|
} else {
|
||||||
// TODO Implement (6.2)
|
// TODO Implement (6.2)
|
||||||
|
rotateLR(p);
|
||||||
}
|
}
|
||||||
} else if (height(p.right) - height(p.left) == 2) {
|
} else if (height(p.right) - height(p.left) == 2) {
|
||||||
if (height(p.right.right) >= height(p.right.left)) {
|
if (height(p.right.right) >= height(p.right.left)) {
|
||||||
// TODO Implement (6.2)
|
// TODO Implement (6.2)
|
||||||
|
rotateL(p);
|
||||||
} else {
|
} else {
|
||||||
// TODO Implement (6.2)
|
// TODO Implement (6.2)
|
||||||
|
rotateRL(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.height = Math.max(height(p.left), height(p.right)) + 1;
|
p.height = Math.max(height(p.left), height(p.right)) + 1;
|
||||||
|
|
Loading…
Reference in a new issue