9
© Pearson Education Limited, 2015
Answer: A
Explanation: A) Answer B does not advance temp to reference the next Node, and is therefore
an infinite loop. Answer C counts the number of items in the list but does not sum up the values
of these items. Answer D has the wrong loop condition and answer E counts all of the items in
the list except for the last one.
For the questions below, assume that a linked list consists of Node objects, where Node has two
instance data, int info and Node next. The linked list stores in the info data, 20, 11, 13, 19, 12,
14 in that order. Assume that Node head references the first item in the list list.
15) What will be returned by return head.next.next.next.info; ?
A) 20
B) 11
C) 13
D) 19
E) 12
16) What is returned by return head.info; ?
A) 20
B) 11
C) 13
D) 19
E) 6
17) What is the result to the linked list of the following instructions? Assume that newNode is a
Node, already constructed.
newNode.data = 1;
newNode.next = head.next;
head.next = newNode;
A) The value 1 is inserted into the linked list before 20
B) The value 1 is inserted into the linked list after 20 and before 11
C) The value 1 is inserted into the linked list after 11 and before 13
D) The value 1 is inserted into the linked list after 13 and before 19
E) The value 1 is inserted into the linked list after 20 and the rest of the list is lost