(Modify BST using Comparator) Revise BST in Listing 25.4 using a Comparator for comparing objects. Define the new class as BST with two constructors: BST(); // Compare elements using their natural...

(Modify BST using Comparator) Revise BST in Listing 25.4 using a Comparator for comparing objects. Define the new class as BST with two

constructors:


BST(); // Compare elements using their natural order


BST(Comparator comparator)


Hint: You need to add a data field for Comparator in the BST class as follows:


protected Comparator c = (e1, e2) ->  ((Comparable)e1).compareTo(e2);

 The lambda expression gives the default comparator using a natural order. You


need to use comparator c to replace e.compareTo(anotherElement) with


c.compare(e, anotherElement) in Listing 25.4.


Nov 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here