
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 solution
Chapter 24 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT



