The stub of BST::contains() should look like this:
bool BST::contains(const Item& it) const {
}
The BST::contains() method should distinguish between the two cases:
- If the BST is empty: return false.
- Otherwise: "pass the buck" by returning whatever myRoot->contains(it) returns.
Since a Node is recursively defined,
Node::contains(it) is a recursive method that should behave as follows:
- If it is less than myItem:
- If myLeft is NULL:
- Otherwise:
- "Pass the buck" by returning whatever myLeft->contains(it) returns.
- Otherwise, if it is greater than myItem:
- If myRight is NULL:
- Otherwise:
- "Pass the buck" by returning whatever myRight->contains(it) returns.
- Otherwise (it is equal to myItem):