Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

# GATE CS 2023 Q 49

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.

1. push the elements of a from a0 to a5 in that order into S.
2. enqueue the elements of a from a0 to a5 in that order into Q.
3. pop an element from S.
4. dequeue an element from Q.
5. pop an element from S.
6. dequeue an element from Q.
7. dequeue an element from Q and push the same element into S.
8. Repeat operation VII three times.
9. pop an element from S.
10. pop an element from S.

The top element of S after executing the above operations is ______________.

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.

1. push the elements of a from a0 to a5 in that order into S.
2. enqueue the elements of a from a0 to a5 in that order into Q.
3. pop an element from S.
4. dequeue an element from Q.
5. pop an element from S.
6. dequeue an element from Q.
7. dequeue an element from Q and push the same element into S.
8. Repeat operation VII three times.
9. pop an element from S.
10. pop an element from S.

The top element of S after executing the above operations is ______________.