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

  Identity using a combinatorial proof

Identity using a combinatorial proof

  Customer with attributes customerid

TNB electric want to create a database with the following entities- Customer with attributes CustomerID, CName, CAddress(Street, City, State, ZipCode) and CTelephone- Location with attributes LocationID, Address (Street, City, State, ZipCode) and Typ..

  List the number (count) of unreserved room

List the guests by guest number, last name, first name and the number of times each guest has stayed in one of our hotels (include all reservations, past, current and future). Arrange the list in order from most-frequent stayer (greatest number of st..

  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..

  Describe at least one possible effect that multithreading

1Describe at least one (1) possible effect that multithreading could have on event-driven programming when you are either developing or using a computer program. Support your response with at least (1) example of the effect of multithreading.

  Compute the cost per equivalent unit for materials

Micro Labs' September 30th general ledger showed a balance of $634,500 in work-in process inventory. $206,500 of the balance was direct materials.

  Find the smallest number ina group of three integer numbers

Write a set detailed, step by step instructions, in english, to find the smallest number ina group of three integer numbers.

  Research a writing guide for forensics organization

Your manager has asked you to research and recommend a writing guide that examiners in your computer forensics organization will use for all official written reports.

  Responsibilities of job when designing digital portfolio

Do you think that your digital portfolio should depend on the job, title, or industry you are planning or working on getting into? Do task and responsibilities of a specific job matter when designing your digital portfolio?

  Executing intrusion detection system

Your company is trying to decide whether to execute intrusion detection system (IDS), or intrusion prevention system (IPS).

  Identify potential obstacles to wireless transmission

Describe the quality of service (QoS) assurance methods critical to converged networks, including RSVP and DiffServ.

  The numbers of three finalists to receive a pr

Write a program to randomly select the numbers of three finalists to receive a pr

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