Java : Count even values in a Binary Search Tree recursively

Posted by user307682 on Stack Overflow See other posts from Stack Overflow or by user307682
Published on 2010-04-02T13:13:42Z Indexed on 2010/04/02 13:23 UTC
Read the original article Hit count: 149

Filed under:
|
|
|
|

Hi,

I need to find out how many even values are contained in a binary tree.

this is my code.

private int countEven(BSTNode root){

if ((root == null)|| (root.value%2==1))
return 0;

return 1+ countEven(root.left) + countEven(root.right);


}

this i just coded as i do not have a way to test this out. I'm not able to test it out at the moment but need an answer so badly. any help is deeply appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about bst