Consider a sequence a of elements a0=1, a1=5, a2=7, a3=8, a4=9, and a5=2.
The following operations are performed on a stack S and a queue Q, both of which are initially empty.
- push the elements of a from a0 to a5 in that order into S.
- enqueue the elements of a from a0 to a5 in that order into Q.
- pop an element from S.
- dequeue an element from Q.
- pop an element from S.
- dequeue an element from Q.
- dequeue an element from Q and push the same element into S.
- Repeat operation VII three times.
- pop an element from S.
- pop an element from S.
The top element of S after executing the above operations is ______________.
View answer
8
Practice Problem
Consider a sequence a of elements a0=2, a1=6, a2=8, a3=9, a4=10, and a5=3.
The following operations are performed on a stack S and a queue Q, both of which are initially empty.
- push the elements of a from a0 to a5 in that order into S.
- enqueue the elements of a from a0 to a5 in that order into Q.
- pop an element from S.
- dequeue an element from Q.
- pop an element from S.
- dequeue an element from Q.
- dequeue an element from Q and push the same element into S.
- Repeat operation VII three times.
- pop an element from S.
- pop an element from S.
The top element of S after executing the above operations is ______________.