The output of Fig. 16.14 shows that Priority-Queue orders Double elements in ascending order. Rewrite Fig. 16.14
Question:
The output of Fig. 16.14 shows that Priority-Queue orders Double elements in ascending order. Rewrite Fig. 16.14 so that it orders Double elements in descending order (i.e., 9.8 should be the highest-priority element rather than 3.2).
Fig. 16.14
Transcribed Image Text:
1 // Fig. 16.14: PriorityQueueTest.java 2 // PriorityQueue test program. 3 import java.util.PriorityQueue; 4 5 6 9 10 [] 12 13 14 15 16 17 18 public class PriorityQueue Test { public static void main (String[] args) { //queue of capacity 11 PriorityQueue queue = new PriorityQueue (); 19 20 21 22 23 } } // insert elements to queue queue. offer (3.2); queue.offer (9.8); queue. offer (5.4); System.out.print("Polling from queue: "); // display elements in queue while (queue.size() > 0) { } System.out.printf("%.1f ", queue.peek()); // view top element queue.poll(); // remove top element Polling from queue: 3.2 5.4 9.8
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (3 reviews)
To order the elements of the PriorityQueue in descending order you need to modify the code to provid...View the full answer
Answered By
Lilian Nyambura
Hi, am Lilian Nyambura, With extensive experience in the writing industry, I am the best fit for your writing projects. I am currently pursuing a B.A. in Business Administration. With over 5 years of experience, I can comfortably say I am good in article writing, editing and proofreading, academic writing, resumes and cover letters. I have good command over English grammar, English Basic Skills, English Spelling, English Vocabulary, U.S. English Sentence Structure, U.K. or U.S. English Punctuation and other grammar related topics. Let me help you with all your essays, assignments, projects, dissertations, online exams and other related tasks. Quality is my goal.
4.80+
378+ Reviews
750+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Ha: Ï 0 Specify an alternative hypothesis for a correlation t-test. For each exercise, decide, at the 10% significance level, whether the data provide sufficient evidence to reject the null...
-
Consider the circuit shown in figure. Find (a) The potential difference between points a and b and (b) The current in the20.0-? resistor. 10.0 2 25.0 V 10.0 2 5.00 2 20.0 2 5.00 2
-
Under certain conditions, the x- and y-components of a magnetic field B are given by the equations Write these equations in terms of polar coordinates. B -ky x + y 2 and B y kx x + y 2
-
(5 points) In a study of purchasing behavior at a small shop, it was found that the probabaty that a purchase is more than $5 is 0.29, the probability that a customer will pay with a credit card is...
-
The treasurer of Joan Osborne Co. has heard that conservatism is a doctrine that is followed in accounting and, therefore, proposes that several policies be followed that is conservative in nature....
-
Firm LD, a calendar year taxpayer, owns 20,000 shares of MXP stock with a $160,000 basis. In November, LD's chief financial officer learned that MXP had just declared bankruptcy. The CFO was unable...
-
A hydrogen/oxygen fuel cell stack produces \(100 \mathrm{~kW}\) of DC power at an efficiency of \(60 \%\) with water vapor as the product. Determine the hydrogen mass flow rate in \(\mathrm{g} /...
-
Pisa Pizza Parlor is investigating the purchase of a new $45,000 delivery truck that would contain specially designed warming racks. The new truck would have a six-year useful life. It would save...
-
26. Consider the AVL tree resulting from sequentially inserting the following numbers into an empty AVL tree: 40, 60, 55, 15, 20, 2, 25, 30. What is the sum of the numbers in the leaf nodes in the...
-
Create a class that mixes two LinkedLists of numbers. Your class should include a static method mixList that takes the references of two LinkedLists as arguments and inserts the numbers in the second...
-
Write a program that uses a String method split to tokenize a line of text input by the user and places each token in a TreeSet. Print the elements of the TreeSet.
-
A debt of $17 500 is repaid by payments of $2850 made at the end of each year. Interest is 8% compounded semi-annually. (a) How many payments are needed to repay the debt? (b) What is the cost of the...
-
Suppose a transistor consists of a very narrow \(p\)-type material sandwiched between two very wide regions of \(n\)-type material. (a) Is the charge on the \(p\)-type region positive or negative,...
-
A \(6.00-\mathrm{mH}\) solenoid is connected in series with a \(1.0-\mu \mathrm{F}\) capacitor and an AC source. The solenoid has internal resistance \(3.0 \Omega\), which can be treated as a series...
-
How might governments around the world collaborate to support green and sustainable finance?
-
(a) If each vertical gray line in Figure \(32.4 b\) represents \(0.020 \mathrm{~s}\), what is the frequency of the oscillation? (b) What is the average potential difference across the capacitor in...
-
What national policies could governments introduce to support green and sustainable finance?
-
A solid round steel bar is machined to a diameter of 32 mm. A groove 3 mm deep with a radius of 3 mm is cut into the bar. The material has a mean tensile strength of 780 MPa. A completely reversed...
-
In Exercises 1558, find each product. (9 - 5x) 2
-
In a byte-oriented protocol, should we first unstuff the extra bytes and then remove the flags or reverse the process?
-
In Example 11.4 (Figure 11.13), assume the round trip time for a frame is 40 milliseconds. Explain what will happen if we set the time-out in each of the following cases. Figure 11.13 a. 35...
-
In a bit-oriented protocol, should we first unstuff the extra bits and then remove the flags or reverse the process?
-
Summer Day Inc. manufactures two models of its hammock, the Superior and the Deluxe. The Superior model requires 15, 0 0 0 direct labour hours and the Deluxe requires 45, 0 0 0 direct labour hours....
-
There are four points A (2, 6), B(6, 4), C(4, 0) and D(0, 2) on the coordinate plane. Identify the pairs of parallel and perpendicular lines
-
What methodologies are employed in the domain of advanced engineering to maximize the efficiency of intricate designs and processes? Explain
Study smarter with the SolutionInn App