Hint 1
- If the current node
r
is null, return 0.
- Define an integer variable to count the number of nodes. Initialize this variable to 1
to count the current node
r
.
- If the left child of the current node is not null, then invoke the algorithm recursively with
parameter equal to the left child of the current node; add the value returned by the recursive
call to your counter.
- Do the same thing with the right child of the current node.
- Return the value of the counter.