Kotlinlearncs.online LogoJava
Return to List

Solve: BinaryTree Count Greater Than

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a method countGreaterThan that accepts a BinaryTree<Int>? and an Int and returns a count of the number of nodes in the tree that contain a value greater than the passed value. If the passed tree is null you should return 0.

For reference, cs125.trees.BinaryTree<T> is defined like this:

As a result, tree.value is an Int which you can compare to the threshold value in the usual way.

Related Lessons

Stuck? You may find these lessons helpful: