Binary Tree Size
Create a method
size that accepts a
cs125.trees.BinaryTree and returns the number of nodes it contains.
size accepts a
BinaryTree<*>?, that is a nullable
BinaryTree that can contain any kind of values.
You'll want to count recursively, identifying both a base case and a recursive step.
cs125.trees.BinaryTree is defined like this:
Don't overthink this! Like many recursive algorithms, the solution is elegant and simple: 4 lines total if you do
You'll also need to import
cs125.trees.BinaryTree for this and similar problems.