Question: Java TreeSet is a balanced binary search tree. In addition to add, remove and search operations as what we have learned in our BinSrchTree, it
Java TreeSet is a balanced binary search tree. In addition to add, remove and search operations as what we have learned in our BinSrchTree, it has a number of other operations. In this programming exercise, we will expand our BinSrchTree class with more similar operationsfrom TreeSet class. Add the following instance methods to BinSrchTreeclass in our unitexampleJavaBSTLinkedand then test them in the driver program:
T first() which returns the first (lowest) item currently in the tree
T last()which returns the last (highest) itemcurrently in the tree
T higher(T item) which returns the least item in the tree strictly greater than the given item, or null if there is no such item
T lower(T item) which returns the greatest item in the treestrictly less than the given item, or null if there is no such item
T ceiling(T item) which returns the least item in the tree greater than or equal to the given item, or null if there is no such element
T floor(T item) which returns the greatest item in the tree less than or equal to the given item, or null if there is no such item
T pollFirst() which retrieves and removes the first (lowest) item, or returns null if the treeis empty
T pollLast() which retrieves and removes the last (highest) item, or returns null if the treeis empty
int size() which returns the number of items in the tree(its cardinality)
BinSrchTree
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
