I have a question about how to write a function that will give me the sum of elements in a manual linked list. I tried it like this but it doesn't work: function insert() inserts elements in list.
public class list {
int head;
List tail;
int sum=0;
int value;
public void insert(int elt){
if(tail == null){
tail = new list();
tail.head = elt;
}
else{
tail.insert(elt);
}
}
public int sum(list head){
if(head!=null){
sum += head;
return tail.sum(head);
}
return sum;
}
}