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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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