Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give a recursive implementation of sumList. A method signature is given below. p

ID: 3684986 • Letter: G

Question

Give a recursive implementation of sumList. A method signature is given below.

public class IntNode {

    private int value;

    private IntNode next;

    public IntNode(int i) { value = i; }

    public int getInt() { return value; }

    public void setInt(int v) { value = v; }

    public IntNode getNext() { return next; }

    public void setNext(IntNode n) { next = n; }

}

public class Sum {

    public static void main(String[] args) {

         IntNode a = new IntNode(10);

        //omitted: code appending more new elements to the list.

    int sum = sumList(a);

    System.out.println("The sum is " + sum);

    }

    //TODO: implement recursive sum implementation.

    public static int sumList(IntNode head) {

Explanation / Answer

public static int sumList(IntNode head)

{

if(head->Next=NULL)

return head->value;

else

returm head->value+sumList(head->next);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote