Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 25, Problem 25.14PE

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

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

BST(Comparator<? super E> comparator)

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

protected Comparator<E> c = (e1, e2) ->

 ((Comparable<E>)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.compar(e, anotherElement) in Listing 25.4.

Blurred answer
Students have asked these similar questions
Based on the following Diagram answer the below questions.   a. What is the Definition of Polymorphism?   b. Extract from the above UML Diagram an example of Overridden method? Explain the meaning of Overridden?   c. Extract from the above UML Diagram above an example of Overloading method? Explain the meaning of overloading?   d. Write an array declaration that is expected to hold up to 10 objects of type Student and Employee?
Construct.
Explain encapsulation briefly
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY