Refactor calcSize
method
This commit is contained in:
parent
63da19757e
commit
7a8e7a973d
1 changed files with 10 additions and 6 deletions
|
@ -94,14 +94,18 @@ 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.left != null) {
|
if (p != null) {
|
||||||
result += calcSize(p.left);
|
result++;
|
||||||
}
|
|
||||||
|
|
||||||
if (p.right != null) {
|
if (p.left != null) {
|
||||||
result += calcSize(p.right);
|
result += calcSize(p.left);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.right != null) {
|
||||||
|
result += calcSize(p.right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue