Concept explainers
Explanation of Solution
Implementation of PrioirtyQueue using Comparator:
//Import the required java package
import java.util.Comparator;
//Define the class Ex24_06
public class Ex24_06 {
//Define the main function
public static void main(String[] args) {
new Ex24_06();
}
//Declare the constructor
public Ex24_06() {
//Create the object for MyPriorityQueue
MyPriorityQueue<String> queue = new
MyPriorityQueue<String>((s1, s2) ->
s1.compareToIgnoreCase(s2));
//Add the elements into queue
queue.enqueue("Macon");
queue.enqueue("Atlanta");
queue.enqueue("Savannah");
queue.enqueue("Augusta");
queue.enqueue("Columbus");
//Check whether the queue size is greater than 0
while (queue.getSize() > 0) {
//Remove the elements from queue
System.out.print(queue.dequeue() + " ");
}
//Create the object for queue1
MyPriorityQueue<String> queue1 = new
MyPriorityQueue<String>((s1, s2) -> s1.length() –
s2.length());
//Add the elements into queue
queue1.enqueue("ABC");
queue1.enqueue("A");
queue1.enqueue("AB");
queue1.enqueue("ABCDE");
queue1.enqueue("ABCD");
System.out.println();
//Check whether the queue1 size is greater than 0
while (queue1.getSize() > 0) {
//Remove the elements from queue
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 24 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
- (10 points) Consider a new secondary method for the Statement component family. Complete the code of the WHILE and CALL cases in the implementation of the instance method aggression below. You may assume that the code for the other cases has already been written. /** * Switches all skip calls with infect calls. * * @ensures * public void aggression () { switch (this.kind ()) { // assume code for BLOCK, IF, and IF ELSE cases already implemented case WHILE: { } this = [#this with skip replaced by infect] } break; case CALL: { break; The del default: { // this will never happen break;arrow_forwardJava programming - Using your knowledge in oop, inheritance, generics, create a generic class from non-generic class then create objects of type (int, sting, boolean, mixed). Write all necessary classes, functions that will return an object of each inherited data typearrow_forwardjava program: University of Bahrain College of Information Technology Department of Computer Science Second Semester, 2020-2021 ITCS214 / ITCS215 / ITCS216 (Data Structures) Assignment 3 Implement generic class ArrayStack as discussed in the lectures having following methods: constructor, push, pop, peek, isEmpty, copy constructor, reallocate (private method). Also add following methods to this class: size: returns number of elements in the stack. contains: Search an element in the stack. If found returns true, else returns false. clear: Deletes all elements of the stack and make it empty stack. Implement generic class ArrayQueue as discussed in the lectures having following methods: constructor, copy constructor, offer, poll, peek, isEmpty, reallocate(private), iterator. Inner class Iter that implements interface Iterator having methods: constructor, hasNext, next. Also add following methods to the ArrayQueue class: size: returns number of elements in the queue. contains: Search…arrow_forward
- C++ Programming (no copy-pastes, please) Write a generic class that receives a parameter T. The class must have as attributes two values that define a pair. The class must also have the following methods:- T getMax(): returns the highest value;- T getMin(): returns the smallest value;- T getSum(): returns the sum of the values. Please comment all the code.arrow_forward(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 SUBMISSIONarrow_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
- Please answer the following question in Python code: Inheritance (based on 8.38) You MUST use inheritance for this problem. A stack is a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stack is often referred to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using Note that this means you may be able to inherit some of the methods below. Which ones? (Try not writing those and see if it works!) Constructor/_init__ - Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top. push() – take an item as input and push it on the top of the stack pop() – remove and return the item at the top of the stack isEmpty() – returns True if the stack is empty, False otherwise [] – return the item at a given…arrow_forwardExplain the Member object files in the libvector library ?arrow_forwardDesign a generic function that returns a minimum element from an array. The function should have two parameters. One is the array of a generic type, and the other is the size of the array. Test the function with an array of int, double, and string values.arrow_forward
- Salesforce Assignment: You are working in company as a junior developer and the manger assign you a task to create the test class of trigger code of the following code will cover all the use case like insert, update, delete. The code is as follows: public class TriggerBasicAssignmentTriggerHelper ( // This method is used to update the vlaue of field C public static void getFiledvalue(List listofValues, Map mapofCoustomobject ){ for (Trigger_Basic_Assignments_ct :listofvalues){ if(mapofCoustomobject == null || t.Field_A_c != mapofCoustomobject.get(t.Id). Field_A_C || t.Field_8_c != mapofCoustomobject.get(t.I if(t.Operator_ '+') t.Field C_c = t.Field_A_c + t.Field_B_c; else if(t.Operator_c *') t. Field C_c = t.Field A_* t.Field_8_c; else if(t.Operator_c == /' && t.Field B_c != 0) t.Field C_c = t.Field A_c / t.Field_B_c; else t.Field C_c = t.Field_A_c - t.Field B_c; I need the test class only.arrow_forwardWrite an OOP complete program in class Overloading constructor, destructor and pointers by using friend function to print the values of x,y,z,n and m ? Note: x=3, y=6, z=9, n=7, m3D25. Using friend class, array of object & for loop.arrow_forwardBased 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?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education