logo CodeStepByStep logo

nodes15

Language/Type: Java ListNodes LinkedLists
Related Links:

Write the code necessary to convert the following sequence of ListNode objects:

list -> [7] -> ... -> [16] /

Into this sequence of ListNode objects:

list -> [42] -> ... -> [42] /

(In other words, set the value of every node to be 42.)

Assume that you are using the ListNode class:

public class ListNode {
    public int data;       // data stored in this node
    public ListNode next;  // a link to the next node in the list

    public ListNode() { ... }
    public ListNode(int data) { ... }
    public ListNode(int data, ListNode next) { ... }
}
Bare code: Write a fragment of Java code as described, without any class or function/method heading around your code.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.