Question: Given a queue Q contains 1, 2, 3, 4, 5 from front to end, and a stack S contains 10, 9, 8, 7, 6 from
Given a queue Q contains 1, 2, 3, 4, 5 from front to end, and a stack S contains 10, 9, 8, 7, 6 from top to bottom. Show the content in the Queue and Stack after the following operations are applied (Clearly label the front, end of the queue and top side of the stack).
while(!S.isEmpty()) { if(S.top() %2 ==0) { Q.enqueue(S.pop()); } else { S.pop(); Q.dequeue(); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
