Refactor calcSize method

This commit is contained in:
Manuel Thalmann 2022-10-31 21:42:10 +01:00
parent 63da19757e
commit 7a8e7a973d

View file

@ -94,7 +94,10 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
} }
protected int calcSize(TreeNode<T> p) { protected int calcSize(TreeNode<T> p) {
int result = 1; int result = 0;
if (p != null) {
result++;
if (p.left != null) { if (p.left != null) {
result += calcSize(p.left); result += calcSize(p.left);
@ -103,6 +106,7 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
if (p.right != null) { if (p.right != null) {
result += calcSize(p.right); result += calcSize(p.right);
} }
}
return result; return result;
} }