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:

ordinary Customers.add("Pranoj"); ordinary Customers.add("Rachel"); ordinary Customers.add("Pratima");

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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: