ProgrammingHard

A stack is implemented with a singly linked list, pushing at the head. The operations are push 1, push 2, pop, push 3, push 4, pop, pop. What is the sequence of popped values?

  1. A. 2, 3, 4
  2. B. 1, 4, 3
  3. C. 4, 2, 3
  4. D. 2, 4, 3

Correct answer: D. 2, 4, 3

The stack is LIFO. 2 is popped first, then 4, then 3, and 1 stays on the stack.

More C Programming questions

Exams that ask this topic