Hello
I'm having problems with two methods of my BST
even though I think the logic is right, both methods return nothing. I even tried a lot of different things but it just won't work..
and for the countEvens method it keeps insisting that the error is in this line
I hope someone could point out my mistakes
I'm having problems with two methods of my BST
public int countEvens() {
return countEvensHelper(root);
}
private int countEvensHelper(BinaryTreeNode p) {
int count = 0;
if (p != null) {
if (((intElement) p.info).getNum() % 2 == 0) {
count = 1;
}
}
return (count + countEvensHelper(p.llink) + countEvensHelper(p.rlink));
}
//*************************************************//
public int countTwoChildren() {
return countTwoChildrenHelper(root);
}
private int countTwoChildrenHelper(BinaryTreeNode p) {
int count = 0;
if (p == null) {
return 0;
}
if (p.llink != null && p.rlink != null) {
count = 1;
}
return count + countTwoChildrenHelper(p.llink) + countTwoChildrenHelper(p.rlink);
}
even though I think the logic is right, both methods return nothing. I even tried a lot of different things but it just won't work..
and for the countEvens method it keeps insisting that the error is in this line
return (count + countEvensHelper(p.llink) + countEvensHelper(p.rlink));
I hope someone could point out my mistakes