Priority queue

Assignment Help Basic Computer Science
Reference no: EM13762365

Queue Behavior :

Write a program that shows what happens when random values go first through an ordinary queue and then through a priority queue. The Queue interface specifies add and remove methods that add elements to and remove elements from a queue. Figure 10.10 shows that when the queue is an instance of the ArrayDeque class, the add method adds elements to the back of the queue and removes elements from the front of the queue. Figure 10.15 shows that another class, PriorityQueue, also implements the Queue interface. Therefore, this other class also implements add and remove methods. Its remove method does the same thing as ArrayDeque's remove method. But its add method is different. When it adds elements, a PriorityQueue inserts them into the queue so that lower-valued elements are always closer to the front. In other words, lower valued elements have priority and "crash" the line. In an initial for loop, generate five random double values and add them to an ordinary queue. In a subsequent while loop, remove all elements from that ordinary queue and add them to a priority queue. In a final while loop, remove all elements from that priority queue. Display the values going into the ordinary queue, coming out of the ordinary queue and going into the priority queue, and coming out of the priority queue, like this:
Sample session:

Input to ordinary queue

0.257
0.804
0.118
0.280
0.199

Output from ordinary queue and input to priority queue

0.257
0.804
0.118
0.280
0.199

Output from subsequent priority queue

0.118
0.199
0.257
0.280
0.804

Random number generation will make your values different from these, but the ordering should be similar.

Reference no: EM13762365

Questions Cloud

Program inputs the first name : You are on the Welcoming Committee at "Geeks -R- Us", you are tasked with gathering basic information on the new potential employees. Write a program that inputs the first name, middle initial (without the period), last name, age, salary and sex o..
Type of introduction : Identifying with the audience is a type of introduction that involves:
Available for mobile and portable internet access : List two of the options that are available for mobile and portable Internet access, and explain their strengths and weaknesses.
Strategies of both informing and persuading : Deliberative speaking uses the strategies of both informing and persuading.
Priority queue : Write a program that shows what happens when random values go first through an ordinary queue and then through a priority queue. The Queue interface specifies add and remove methods that add elements to and remove elements from a queue.
Write paper on minors should be tried as adults for crimes : Write a paper on Minors Should Be Tried As Adults For Violent Crimes.
Synchronization between the database and the transaction log : A point of synchronization between the database and the transaction log is called a(n): An ACID transaction is one that is:
Create constraints-speakers : 1. Because occasions create constraints, speakers must limit their strategic choices to what the audience expects.
Type of visual aid : Helga wants to show how the rate of traffic accidents changes for drivers as they advance in age. What type of visual aid would best represent this information?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explaining actionscript developer

What do you believe the following comment means for ActionScript developer: "you are used to having to define object methods and properties in class structure before using them in instance.

  A file containing the case study evaluation report

As an external consultant, you have been hired by a competitor, OCBIN, to analyze the way NIBCO implemented its SAP ERP system and to identify issues that when addressed would create a better outcome. You are to present your analysis in the case stud..

  Research and submit an encryption algorithm

What kind of encryption could you use that would result in the encrypted text being something other than alphabetic characters or numbers?

  Suggest the maximum number of slides

Suggest the maximum number of slides

  Create a short email message on the importance of a college

Email the message to your instructor using the email address provided by them and carbon copy an alternate email address (you can use your own address).

  The it environment

The IT environment

  Execute one set of statements if the condition is true

You need to test a condition and then execute one set of statements if the condition is true.

  Design sequential circuit that continuously compute function

Design a sequential circuit that continuously computes the function 2X + Y where the variables X and Y are 2 three-bit unsigned integers each available on a serial interface. A special external data signal (DATA_READY) is asserted whenever each of..

  Design a 3-bit counter, which can count either up or down

Design a 3-bit counter, which can count either up or down. The input has a clock, and a signal U. When U = 1, the counter counts up; when U = 0, the counter counts down. For example, assume the current counter Q(t) = 011. If U(t) = 0, then Q(t+1) = 0..

  How many clock cycles are needed

Indicate data dependency in the above code. Assuming there is no forwarding in the pipeline, how many clock cycles are needed to finish the program? If full forwarding is used, how many clock cycles are needed?

  How implement memory allocation with strings

how implement memory allocation with strings.

  Which domain local groups might you create

Habibi's has a small network of 20 client workstations and a Windows Server 2008. Seven of those workstations are inside the restaurant and are used by the table servers to place customer orders. Three of the workstations are used by the owner and th..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd