Part III (40 points): Queues of the Given a stack s and whose items are used sam
ID: 3823698 • Letter: P
Question
Part III (40 points): Queues of the Given a stack s and whose items are used same type, where a circular queue type conventions are is actually int. The subscript of the too is the of the top item, Front (F) location front item, and Back subscript of the empty behind the actual item. is the operate in the same way as back The functions they do our text. The first diagram shows the initial states of the stack and queue. For each of the two groups of statements, show in the initial state stack and queue the results of executing the statements, crossing out any and B which may be deleted by the statements, and rewriting F, blank as to show their current values. T, stack and queue Then copy into the execution of the final status of the stack and queue after the statements The statements in each group are executed in sequence group Initial states: but eachExplanation / Answer
Solution:-
(1) Q.enqueue(S.top());
the top element of stack 4 is inserted in queue. Queue back is updated.
(2) Q.enqueue(S.top()*2);
the top element of stack 4 is inserted in queue after Multiplying by 2 that is 8. Queue back is updated.
(3) Q.dequeue();
The front element of queued is deleted and front is updates to 3.
(4) Q.Enqueue(Q.front());
the front element of queue 3 is inserted in queue. Queue back is updated.
After executing the above four operations the final status of the Stack and the queue are as follows -
Stack -
T
Queue -
B F
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(1) S.push(Q.front());
Queue front element 6 is pushed to stack. Top is updated.
(2) S.push(S.Top());
Stack top element 6 is pushed to stack again. Top is updated.
(3) S.pop();
Stack top is popped from stack. Top is updated.
(4) Q.dequeue();
The front element of queue 6 is removed. Front is updated.
(5) S.push(Q.front());
The front element of queue 3 is pushed to stack. Top is updated.
After executing the above four operations the final status of the Stack and the queue are as follows -
Stack -
T
Queue -
B F
6 4