counting nodes in binary search tree

counting nodes in binary search tree
ref‮al:ot re‬utturi.com
// Java count the number of nodes in binary tree
public int countNode(Node root){

    //base case
    if(root==null)
        return 0;

    //recursive call to left child and right child and
    // add the result of these with 1 ( 1 for counting the root)
    return 1 + countNode(root.left) + countNode(root.right);
}
Created Time:2017-09-04 07:28:54  Author:lautturi