Practice problem
Data Structures: Stacks
Let and be stacks. Suppose contains the elements in that order, with on top and on the bottom. Now suppose the following piece of code is called:
while(!is_empty(S)) push(T,pop(S));
Here is_empty(S) checks to see whether S is an empty stack, pop(S) removes the top element from S, and push(T, e) pushes the element e onto the stack T.
What elements, and in what order, will be stored inside the stack T after this program has finished execution?