Suppose that we say:

Cons lst = null;
for (int i = 0; i < 3; i++ )
    lst = cons( i, lst );

What is the value of lst?

  • A: (1 2 3)
  • B: (3 2 1)
  • C: (0 1 2)
  • D: (2 1 0)
  • E: (((2) 1) 0)

    Answer: D

    cons puts one new item onto the front of an existing linked list.

    Because of this, it builds a list in backwards order compared to the order of insertion.

    As the loop proceeds, the value of lst is:

    Page-10    Prev    Next    Page+10