diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/SortedBinaryTree.java b/app/src/main/java/ch/nuth/zhaw/exbox/SortedBinaryTree.java index 6f9d877..8893dda 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/SortedBinaryTree.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/SortedBinaryTree.java @@ -74,14 +74,19 @@ public class SortedBinaryTree> implements Tree { } protected int calcHeight(TreeNode node) { - int result = 0; + if (node == null) { + return 0; + } else { + int result = 1; - if (node.left != null || node.right != null) { - result = Stream.of(node.left, node.right).filter( - (innerNode) -> innerNode != null).mapToInt((innerNode) -> calcHeight(innerNode)).max().getAsInt(); + if (node.left != null || node.right != null) { + result += Stream.of(node.left, node.right).filter( + (innerNode) -> innerNode != null).mapToInt((innerNode) -> calcHeight(innerNode)).max() + .getAsInt(); + } + + return result; } - - return result + 1; } public int height() {