Question: - Implement the size() method (along with a recursive method) for the BinarySearchTree class developed in lecture. - Implement the contains() method (along with a
- Implement the size() method (along with a recursive method) for the BinarySearchTree class developed in lecture.
- Implement the contains() method (along with a recursive method) for the BinarySearchTree class developed in lecture.
- Implement the toString() method (along with a recursive method) for the BinarySearchTree class developed in lecture that returns a string containing all of the elements in sorted order.
- Implement a recursive method, max() that returns the largest value of the tree.
- Implement a recursive method, min() that returns the smallest value of the tree.
**This is what we implemented in class
public class BinarySearchTree
Node(E value, Node
private Node
public boolean isEmpty() { return root==null; }
public int size() { return size(root); }
private int size(Node
public boolean add(E value) { if(value==null) { throw new NullPointerException("Nulls not welcome here"); } boolean isChanged; if(root==null) { root = new Node<>(value); isChanged = true; } else { isChanged = add(root, value); } return isChanged; }
private boolean add(Node
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
