Question: The pseudocode below would reverse the contents of the stack s1. (assume the stack & queue store ints). Stack s1 = new Stack(); // assume
The pseudocode below would reverse the contents of the stack s1. (assume the stack & queue store ints).
Stack s1 = new Stack(); // assume s1 is populated with data somehow Queue q1 = new Queue();
while ( ! s1.isEmpty() ) { // move stack contents to q1 int item = s1.pop(); q1.enqueue( item );
}
while ( ! q1.isEmpty() ) { // move queue contents to s1 int item = q1.dequeue(); s1.push( item )
}
Assume stack s1 and queue q1 have been populated with data.
Write client pseudocode (using any combination of extra stacks & queues ) to solve the following:
1.Reverse the stack s1
2.Remove all even numbers from the stack s1
3. Nondestructively make a copy of q1. Name the copy q2. (Nondestructively means that q1 is the same before and after the copy is made).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
