Specification for a Queue Interface
Exercises:
Trace the following fragment for a Stack<String> s and an empty queue q (type Queue<String>).
while (!s.empty()){ item = s.pop(); q.offer(item); } while(!q.isEmpty()){ item = q.remove(); s.push(item); } |
![]() |
a. What is stored in stack s after the first loop executes? What is stored in queue q after the first loop executes?
b. What is stored in stack s after the second loop executes? What is stored in queue q after the second loop executes?