Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Illustrate the result of each operation in the sequence DEQUEUE(), ENQUEUE(S, 0)

ID: 3688091 • Letter: I

Question

Illustrate the result of each operation in the sequence DEQUEUE(), ENQUEUE(S, 0), ENQUEUE(S, 9), DEQUEUE(), ENQUEUE(S, 2), DEQUEUE(), ENQUEUE(S, 7), ENQUEUE(S, 1), ENQUEUE(S, 3), and ENQUEUE(S, 4) on an initially empty queue Q stored in array Q[1..4].

Use this as a model...

12 3 4567 8 9 10 11 12 15 6 9 8 4 headlQ] = 7 rai/IQ] = 12 12 3 456789 10 11 12 (b) 3 5 15 6 9 8 4 17 taillQ]-3 head[Q]=7 1 2 3 45 67 8 9 10 11 12 3 515 6 9 8 4 17 taill0l 3 tail[Q] = 3 head[Q] = 8 Figure 10.2 A queue implemented using an array Q[L.12]. Queue elements appear only in the lightly shaded positions. (a) The queue has 5 elements, in locations Q [7··11 ]. (b) The configuration of the queue after the calls ENQUEUE O.17), ENQUEUE Q.3), and ENQUEUE Q, 5). (c) The configuration of the queue after the call DEQUEUE Q) returns the key value 15 formerly at the head of the queue. The new head has key 6.

Explanation / Answer

dequeue will remove one element from stack

enqueue will add one element to the stack that 0 will be added to stack S

this will add element 9 to the stack

this will remove the top ost element in the stack i.,e 9 will be removed

add element 2 to the stack

remove 2 from stack

add 7,1,3,4 to the stack