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

  Simpl program prove by structural induction

Let c be an arbitrary SIMPL program and assume that judgment ßs' holds for some store s'. Prove by structural induction that x Î pre(s'), where pre(s') denotes the preimage of s'.

  Using a pld, develop an i/o port decoder

Using a PLD, develop an I/O port decoder that generates the following high-bank I/O strobes: 300DH, 300BH, 00B6H, and 00EEH.

  Draw a hierarchy chart and plan the logic

Draw a hierarchy chart and plan the logic for a program for the sales manager of The Potato Furniture Company.The manager needs a program to dertemine the profit on any item sold,input includes the wholesale price and retail price for an item ..

  Explaining statement for security policy

Write a statement for security policy for the following:Let LAN for small 100-person business, Pixel Inc. Business occupies one floor in office building. Everybody has a computer on his or her desk.

  What are the five different approaches to risk

What are the five different approaches to risk? What are the pros and cons of each strategy? Support your answer with solid reasoning class is cmgt 400

  Consider a hypothetic experiment

One of the most widely used applications of spectroscopy is for the quantitative determination of the concentration of biological molecules in solution. The absorbance of a solution.

  Explain why your technique is lossless and not lossy

Devise a way to compress the following list of last names using a lossless technique. Describe your method and show the compressed list. Explain why your technique is lossless and not lossy.

  Why does this type of delegation make sense

Which is preferable, to delegate permissions to an individual or to a group? Why does this type of delegation make sense?

  Draw mind map to show risks and actions and strategies

Draw a mind map to show the risks and the actions and strategies that would ensure the integrity of your data, and the optimisation of a computer.

  Problems a team may encounter during a project life cycle

Discussion, consider some of the problems a team may encounter during a project life cycle: Question: What are some of the typical problems a project team may encounter during a project's life cycle?

  Accuracy of data input is important what method of data

prepare a 2- to 3- page apa paper that includes the followingmiddot accuracy of data input is important. what method of

  Create an employee class

Create an Employee class

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