Exercise #1: Pseudocode
Formulate the following verbal description in pseudocode:
To reverse the order of the elements on a stack S with the help of a queue:
- In the first phase, pop one element after the other from S and enqueue it in queue Q until the stack is empty.
- In the second phase, iteratively dequeue all the elements from Q and push them onto the stack.
As a result, all the elements are now in reversed order on S.
|