Question: java A singly linked list of integers has a dummy head node, followed by a node with 8 , followed by a node with 9
A singly linked list of integers has a dummy head node, followed by a node with 8 , followed by a node with 9 , followed by a node with 1 , and a final node with 3. h8>9>13 a) What does the following code fragment output for the list above? What does it output in general? What must be true about this list to avoid a runtime ecror? Node p= head; while (p.next != null) \& p=p.next; ] System.out.println(p.data); b) The following code outputs the sum of all of the values in the linked list. Explain the unintended side effect that occurs when this code is run. Then rewrite the code to avoid this side effect. int s=0 : while (head != null) \{ s+= head.data; head = head.next; J System.out.println(s)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
