7.2k views
2 votes
The following Integer values are pushed onto a stack, s. The values are pushed onto s in the order that they appear below (left to right).

1 7 4 6 10 9

Assume the following declaration has been made.
PriorityQueue priQue new PriorityQueuecinteger> :

Values are popped off the stack, s, and as each value is popped off the stack, it is inserted into the priority queue, priQue. The following code is then executed.

while (!priQueue.isEmpty()){
System.out.println (priQue.remove ())

The numbers printed to the screen would be: ______

User Entity
by
8.6k points

1 Answer

4 votes

Answer:

9 10 6 4 7 1

Step-by-step explanation:

When the values are pushed to the stack they would end up in the stack in the same order as they go in.

1 7 4 6 10 9

when elements are popped from a stack they are removed from the end to the beggining of the stack, and since these elements are being added to the priorityQueue then priQue will have the following order

9 10 6 4 7 1

this will also be the order that the numbers will be printed out from left to right since priorityQueue remove method, removes the elements from left to right.

User Gavin G
by
7.9k points