Concept explainers
Explanation of Solution
Step 1: Define a static comparator class “DecOrder”.
Step 2: Inside that function declare a method “compare” to compare the values. This method returns the value.
Step 3: Outside the method, declare a variable to hold the capacity value.
Step 4: Create an object for the class “DecOrder”.
Step 5: Create a priority queue.
Defining a comparator class “DecOrder”:
//Define a static comparator class named "DecOrder"
static class DecOrder implements Comparator<Integer>
{
//Function definition to compare values
public int compare(Integer x, Integer y)
{
//Return the value
return y...
Want to see the full answer?
Check out a sample textbook solutionChapter 21 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Declare and implement 5 classes: FloatArray, SortedArray,FrontArray, PositiveArray & NegativeArray.1- The FloatArray class stores a dynamic array of floats and itssize. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the arrayelements from the file (ifstream) and add them to the array.- A destructor to deallocate the array2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add tothe array then sort but rather add in the right place.3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the front of the…arrow_forwardDeclare and implement 5 classes: FloatArray, SortedArray,FrontArray, PositiveArray & NegativeArray.1- The FloatArray class stores a dynamic array of floats and itssize. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the arrayelements from the file (ifstream) and add them to the array.- A destructor to deallocate the array2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add tothe array then sort but rather add in the right place.3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the front of the…arrow_forwardWrite the definitions of the member functions of the classes arrayListType and unorderedArrayListType that are not given in this chapter. The specific methods that need to be implemented are listed below. Implement the following methods in arrayListType.h: isEmpty isFull listSize maxListSize clearList Copy constructor Implement the following method in unorderedArrayListType.h insertAt Also, write a program (in main.cpp) to test your function.arrow_forward
- Add the following method in the BST class that returns aniterator for traversing the elements in a BST in preorder./** Return an iterator for traversing the elements in preorder */java.util.Iterator<E> preorderIterator()arrow_forwardDesign and implement a Java class named Book with two data members: title and price. The class should have suitable constructors, get/set methods, and the toString method. Design and implement another Java class named BookShelf which has an ArrayList data member named bookList to store books. The class should have suitable constructors, get/set methods, and the toString method, as well as methods for people to add a book (prototype: addBook(Book book)), remove a book (prototype: removeBook(Book book)), and search for a book (prototype: findBook(Book book)). Test the two classes by creating a Bookshelf object and five Book objects. Add the books to the bookshelf. Display the contents of the bookshelf. Test the removeBook and findBook methods as well. Take screenshots of your tests and submit them with your Java code (not the whole project)arrow_forwardTaskDeclare and implement 5 classes: FloatArray, SortedArray,FrontArray, PositiveArray & NegativeArray.1- The FloatArray class stores a dynamic array of floats and itssize. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the arrayelements from the file (ifstream) and add them to the array.- A destructor to deallocate the array2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add tothe array then sort but rather add in the right place.3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the front of…arrow_forward
- c# programMake a class called Employees, with attributes Name, Gender, Experience, Salary and ID.Make a delegate called EligiblePromo. This delegate takes an employees object as a parameter and returns a boolean value indication whether or not the employee should be promoted.Make a PromoteEmployee() method that takes an arraylist of Employees and delegate of type EligiblePromo as parametersNB: PromoteEmployee() methos loops through each Employees object and passes it to the delegate(25)arrow_forwardDevelop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.arrow_forwardSECTION C(JAVA)Look at the class definitions below and answer the questions based on it:class Node{// attributesint ID;String name; Node left; // left child Node right; // right child}class BinarySearchTree{// attributesNode root;// methodssearch(int key, Node root);void insert(int key, Node root);void delete(int key, Node root);}Write code for a method split(int key, Node root) that divides a binary searchtree into two parts. The split should occur at key and create two new binary searchtrees. Return the root of each resulting tree.Test your code with the input in the worked exampleBELOW IS THE INPUT:// id, name41, notes11, personal61, work30, shopping5, recipes55, proposal70, thesis10, muffins43, draftarrow_forward
- Use NetBeans Note for all the above User-Defined Classes: • Provide appropriate validation code so the right values get populated in the instance variables. For example, the payrate should not be negative. Write a Java application (Client) program with a static method called generateEmployees( ) that returns a random list of 10 different types of Employee objects. You would use an ArrayList to store the employee objects that will be returned. Use a for loop to populate randomly different types of employee objects with some random data. You could possibly think of a range of values like 1 – 4. If random value is 1, create a HourlyEmployee object with some randomly generated data, if 2, a SalariedEmployee object with some random data and so on. I would leave it to your ingenuity to generate and populate these different Employee objects with other data like name etc. As these objects are generated, add them to your data structure (array or ArrayList that you are using). Finally, the…arrow_forwardHi, can you please use java for this questionarrow_forwardComputer sciencearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning