solved s06 ex04

This commit is contained in:
navid.sassan 2020-11-02 17:03:55 +01:00
parent 01498f094e
commit 4fd8fb4f83

View File

@ -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.