Question: //trying to make a recursive call to function to get a sum of all nodes in a linked list, having problems calling the recursive function

//trying to make a recursive call to function to get a sum of all nodes in a linked list, having problems calling the recursive function sum from main method, explanations appreciated, thanks.

import java.util.*; public class LinkedListSum {class Node { //our constructor for our Nodes int item; Node next; } public int sum (Node x) {int rest=0; if (x==null) { return 0; } else { rest= sum(x.next); } return rest + x.item; }

public static void main(String[] args) { int resultsum= sum() }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!