Listing 5: countHelper() written as a nested function.
class Tree { Tree left; Tree right; } void doCount(Tree t) { int count = 0; void countHelper(Tree t) { while (t) { count++; countHelper(t.right); t = t.left; } } countHelper(t); printf("number of nodes in tree = %d\n", count); }