Assume an ordinary queue has been declared with the Queue interface and instantiated with the ArrayDeque class.
Question:
Assume an ordinary queue has been declared with the Queue interface and instantiated with the ArrayDeque class. Also, assume a priority queue has been declared with the Queue interface and instantiated with the PriorityQueue class. Figure 10.15 shows that the PriorityQueue class also implements the Queue interface. Therefore, the PriorityQueue 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 priority queue inserts them into the queue so that lower-valued elements are always closer to the front. In other words, in a priority queue, lower-valued elements have priority and “crash” the line. Given this understanding, show the output produced by the following code fragment:
You should be able to do this by just thinking about it, but feel free to complete and run a program to check your answer.
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean