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_forwardAdd 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_forward
- TaskDeclare 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_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_forwardComputer sciencearrow_forward
- Programming Exercise 8 asks you to redefine the class to implement the nodes of a linked list so that the instance variables are private. Therefore, the class linkedListType and its derived classes unorderedLinkedList and orderedLinkedList can no longer directly access the instance variables of the class nodeType. Rewrite the definitions of these classes so that these classes use the member functions of the class nodeType to access the info and link fields of a node. Also write programs to test various operations of the classes unorderedLinkedList and orderedLinkedList. template <class Type>class nodeType{public:const nodeType<Type>& operator=(const nodeType<Type>&);//Overload the assignment operator.void setInfo(const Type& elem);//Function to set the info of the node.//Postcondition: info = elem;Type getInfo() const;//Function to return the info of the node.//Postcondition: The value of info is returned.void setLink(nodeType<Type>…arrow_forwardIN c++ See the specification of the HugeInt class.Complete the implementation of this class.Provide a driver to demonstrate the features of the HugeInt class. HugeInt.h #ifndef HUGEINT_H_#define HUGEINT_H_ enum SignType {PLUS, MINUS}; class HugeInt{private: struct Node { int digit; // SINGLE DIGIT ONLY ie: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Node *next; // Next More Significant Digit }; /* Integer 345 is stored in List: 3 <- 4 <- 5 <- digits Integer 123 is stored in List: 1 <- 2 <- 3 <- digits To add: add the least significant digits, potentially keeping track of a carry value. Then move to the next left nodes in both HugeInts. Add these and the carry. Create a new carry value. Continue until both HugeInt lists are empty. If one list is empty, keep processing the non-empty list. */ Node *digits; //Linked list of digit nodes SignType sign; //enum of the sign of the HugeInt int…arrow_forwardjava quetion Write a generic AddressBook<E extends Person> class that manages a collection ofPerson objects. The AddressBook class is a generic class limited to person objects. Forexample, once you instantiate an AdressBook of Student objects, you cannot add anyother type of person objects into that instance of address book.The AddressBook should have methods to add, delete, or search for a Person objects inthe address book.• The add method should add a person object to the address book. Make sure thatthe add method does not add duplicate person objects to the address book.• The delete method should remove the specified person object from the addressbook.• The search method that searches the address book for a specified person andreturns the list of persons matching the specified criteria. The search can be doneeither by first name, last name, or person id.Write an AddressBookTester class to test your class.arrow_forward
- Can anyone please solve this question asap ? Thank yoyuIn this question, you are required to implement singly linked list and its concepts to solve the problems of a departmental store described in the scenario given below:A departmental store has a variety of products to sell. Each product type has a unique ID and price associated with it (for example soaps can have an ID of 1 and price of 50 etc.). A customer comes to the store and starts putting items in his/her shopping cart. Once all theitems have been placed in the shopping cart, the customer then proceeds to checkout but before that, he/she will sort (in ascending order of IDs) the shopping cart’s items and proceed to remove all the duplicate items from the shopping cart, that is if two soaps have been added to the cart, only 1 will be kept. At the checkout counter, he/she will then remove items from the cart by removing from the end of the shopping cart (linked list). A bill for that customer is then generated and printed.You…arrow_forwardCourse: Data Structure and Algorithms Language: C++ Question is well explained Question #2Implement a class for Circular Doubly Linked List (with a dummy header node) which stores integers in unsorted order. Your class definitions should look like as shown below: class CDLinkedList;class DNode {friend class CDLinkedList;private int data;private DNode next;private DNode prev;};class CDLinkedList {private:DNode head; // Dummy header nodepublic CDLinkedList(); // Default constructorpublic bool insert (int val); public bool removeSecondLastValue (); public void findMiddleValue(); public void display(); };arrow_forwardIdentify the True statements: Code for the finally block is required in every try-catch-finally sequence. The programmer cannot control the location the objects in an ArrayList. An interface can extend other interfaces. Code in finally block is only executed after the exception is thrown. An ArrayList can only sort its objects if the class implements the Comparable interface.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning