solved s06 ex04
This commit is contained in:
parent
01498f094e
commit
4fd8fb4f83
@ -1,5 +1,7 @@
|
||||
package ch.zhaw.ads;
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
public class AVLSearchTree<T extends Comparable<T>> extends SortedBinaryTree<T> {
|
||||
|
||||
// /**
|
||||
@ -13,6 +15,14 @@ public class AVLSearchTree<T extends Comparable<T>> extends SortedBinaryTree<T>
|
||||
return calcHeight(root);
|
||||
}
|
||||
|
||||
public boolean balanced(TreeNode<T> node) {
|
||||
if (node == null) {
|
||||
return true;
|
||||
} else {
|
||||
return Math.abs(calcHeight(node.left) - calcHeight(node.right)) < 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert into the tree; duplicates are ignored.
|
||||
* @param element the item to insert.
|
||||
|
Loading…
x
Reference in New Issue
Block a user