Assume an ordinary queue has been declared with the
Queueinterface and instantiated with the
ArrayDequeclass. Also, assume a priority queue has been declared with the
Queueinterface and instantiated with the
PriorityQueueclass. Figure showed that the
PriorityQueueclass also implements the
Queueinterface. Therefore, the
PriorityQueueclass also implements
addand
removemethods. Its
removemethod does the same thing as
ArrayDeque’s removemethod. 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:
ordinaryQueue.add(8);ordinaryQueue.add(3);ordinaryQueue.add(12);System.out.println(ordinaryQueue.remove());ordinaryQueue.add(5);while (!ordinaryQueue.isEmpty()){ priorityQueue.add(ordinaryQueue.remove());}while (!priorityQueue.isEmpty()){ System.out.println(priorityQueue.remove());}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.
Figure Part of the top of the Java collections framework interface hierarchy

We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.