X290: Binary Search Tree Small Count Exercise
Write a recursive function BSTsmallcount
that, given a BST
and a value key
, returns the number of nodes having values
less than key
. Your function should visit as few nodes in the
BST as possible.
Here are methods that you can use on the BinNode
objects:
interface BinNode {
public int value();
public void setValue(int v);
public BinNode left();
public BinNode right();
public boolean isLeaf();
}
Your Answer:
Feedback
Your feedback will appear here when you check your answer.