Question: You are asked to imitate queue Q by using two stacks S1 and S2. Explain, step-by-step, how enqueue and dequeue can be achieved. (20%) Recall

You are asked to imitate queue Q by using two stacks S1 and S2. Explain, step-by-step, how enqueue and dequeue can be achieved. (20%) Recall that a stack abstract data type has the following operations: // push an element x into stacks push(s, x); // pop an element from stacks pop(); // return the topmost element of stack s value = top(S); // return the topmost element of stack S and pop the element as well value = topandpop(S); // check whether the stack is empty or not is_empty(s)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
