S and Q are a stack and a priority queue of integers, respectively. The priority of an element C joining the priority queue Q is computed as C mod 3. In other words, the priority numbers of the elements are either 0 or 1 or 2. Given A, B, and C to be integer variables, what is the output of the following code? The procedures are similar to those used in illustrative problems 5.1 and 5.2. However, the queue procedures are modified to appropriately work on a priority queue. 1.A = 10 2.B = 11 3.C = A+B 4.while (C < 110) do 5. if (C mod 3) = 0 then PUSH (S,C) 6. else ENQUEUE (Q,C) 7. A = B 8. B = C 9. C = A + B 10.end 11.while not EMPTY_STACK (S) do 12. POP (S,C) 13. PRINT (C)
S and Q are a stack and a priority queue of integers, respectively. The priority of
an element C joining the priority queue Q is computed as C mod 3. In other words,
the priority numbers of the elements are either 0 or 1 or 2. Given A, B, and C to be
integer variables, what is the output of the following code? The procedures are
similar to those used in illustrative problems 5.1 and 5.2. However, the queue
procedures are modified to appropriately work on a priority queue.
1.A = 10
2.B = 11
3.C = A+B
4.while (C < 110) do
5. if (C mod 3) = 0 then PUSH (S,C)
6. else ENQUEUE (Q,C)
7. A = B
8. B = C
9. C = A + B
10.end
11.while not EMPTY_STACK (S) do
12. POP (S,C)
13. PRINT (C)
14.end
15.while not EMPTY_QUEUE (Q) do
16. DEQUEUE (Q, C)
17. PRINT (C)
18.end
Step by step
Solved in 2 steps with 1 images