Q:
Compute the sum of all the values in the nodes of a single linked list
A:
public int getSum(Node head)
{
if (head == null) return 0;
else
return getSum(head.next) + head.value;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment