previous | start | next

Breaking put "problem" into subproblems

The put method is a slightly different pattern since it changes the tree while the size method does not. This means that put must change some links.

However, put uses the same approach of using a public method and a private, recursive helper method.

The recursive solution the "problem" of putting x into the whole tree reduces to putting x into the appropriate subtree:

if x < root.key, put x in the left subtree
else if x > root.key, put x in the right subtree


previous | start | next