ISRO Computer Science (CSE) 2015 - Question 11

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2015

If the sequence of operations - push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), pop are performed on a stack, the sequence of popped out values

  • A. 2, 2, 1, 1, 2
  • B. 2, 2, 1, 2, 2
  • C. 2, 1, 2, 2, 1
  • D. 2, 1, 2, 2, 2

Answer: A. 2, 2, 1, 1, 2

Explanation: 1. Push 1 [1]. 2. Push 2 [1,2]. 3. Pop -> 2 [1]. 4. Push 1 [1,1]. 5. Push 2 [1,1,2]. 6. Pop -> 2 [1,1]. 7. Pop -> 1 [1]. 8. Pop -> 1 []. 9. Push 2 [2]. 10. Pop -> 2 []. Sequence: 2, 2, 1, 1, 2.

| | All questions of ISRO Computer Science (CSE) 2015