Originally posted by Taylor Woods:
I'm not sure about the part "insert" I kept getting an error that says I need to "return" something at the end of the "insert" method. So..I just put "return left" and "return right" even though I don't really know what they do in the code.
What is insert's contract? Which TreeNode is it supposed to return? One likely possibility is that it should return the TreeNode that gets created to hold the value. This code will not do that, but it's very close.
Also, what happens if insertValue is already in the tree?
This method can be rewritten without the root parameter. As it stands, the root node is iterating the whole tree. Compare it to how the insert() method recurses on each node down the tree.
From this tree, I want to delete the node containing 2, the node containing 23, and the node containing 1.
The remove algorithm is tricky since you have to adjust the tree; you can't simply delete the node in place. Instead, you must adjust the two subtrees. Have you read descriptions of how to do this in your book or online? There's a fairly simple trick to it with a binary tree.
In fact, java.util.TreeMap uses a binary tree for the keys. Check it out and see if you can give it a go. Draw out what needs to happen and then write it in code.