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
: A designer in 3D graphics company wants to design a matrix as a two-dimensional array. The size of 2D array could be the last two digit of arid number. Initially he creates a class matrix that provides the member function to check that no array index is out of bounds. Make the member data in the matrix class a 10-by-10 array. A constructor should allow the programmer to specify the actual dimensions of the matrix (provided they’re less than 10 by 10). The member functions that access data in the matrix will now need two index numbers: one for each dimension of the array. Here’s what a fragment of a main() program that operates on such a class might look like: If my Arid Number is  20-Arid-254 then:    // in case of zero consider next digit  matrix m1(5, 4); // define a matrix object  int temp = 12345; // define an int value m1.put(3, 4, temp); // insert value of temp into matrix at 3,4 temp = m1.get(3, 4); // obtain value from matrix at 3,4
(Find the nonleaves) Java Define a new class named BSTWithNumberOfNonLeaves that extends BST with the following methods: /** Return the number of nonleaf nodes */public int getNumberofNonLeaves() // BEGIN REVEL SUBMISSION class BSTWithNumberOfNonLeaves<E> extends BST<E> { /** Create a default BST with a natural order comparator */ public BSTWithNumberOfNonLeaves() { super(); } /** Create a BST with a specified comparator */ public BSTWithNumberOfNonLeaves(java.util.Comparator<E> c) { super(c); } /** Create a binary tree from an array of objects */ public BSTWithNumberOfNonLeaves(E[] objects) { super(objects); } public int getNumberOfNonLeaves() { return getNumberOfNonLeaves(root); } /** Returns the number of non-leaf nodes */ private int getNumberOfNonLeaves(TreeNode<E> root) { // WRITE YOUR CODE HERE } } // END REVEL SUBMISSION
Please read the main function and define a class CStudent. (object array, static member, string) Please do not change the main function and complete the program given. 【Description】 Please read the main function and define  a class CStudent.  In the main funciton, two arrays of the ojbect of CStudent are define.  Please analyze the call of constructor and destructor in the process of creating and releasing objects. 1. CStudent has two private member variables:stirng name, int age.  2. CStudent has a static member count. It will be incremented by 1 when the object is created and decremented by 1 when the object is destroyed. 3. The constructor function should output "*** is contructing". The destructor function should output “*** is destructing”. "***" indicates the name of the current CStudent object.     【Input】 No input   【Output sample】 There are 0 students. noname is contructing noname is contructing noname is contructing noname is contructing noname is contructing name:noname…
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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