Queue Behavior *Programming*ieas2010
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:
Input to ordinary queue
Output from ordinary queue and input to priority queue
Output from subsequent priority queue
Random number generation will make your values different from these, but the ordering should be similar.
This is information of the book if needed.
- 6 years ago
- Calculus Question
- Principles of Accounting II, ACCT221, Section 4010, Quiz #2 (Take Home), Chapters 17, 18, 19 & 20
- One of the primary differences between U.S. GAAP and international accounting standards is that the use of LIFO is permitted for U.S. companies. How does LIFO affect a company’s financial results? In your opinion, should LIFO be a permitted inventory cost
- need this in 30 min or less
- Improving Decision Making: Evaluating Security Outsourcing Services Chapter 8, p. 292 Software skills: Web browser and presentation software Business skills: Evaluating business outsourcing services This...
- Description and question
- quiz (english writing )
- WileyPLUS basic accounting
- MATH133 (Need within 12 hours)