ProgrammingModerate

Building a list from n values by inserting each new node at the head is O(1) per insert. What is the order of the values when read from the head after inserting 1, 2, 3, 4 in that order?

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

Correct answer: D. 4, 3, 2, 1

Each new node goes in front of the previous head, so the last value inserted is read first.

More C Programming questions

Exams that ask this topic