Technical Interview

Tips, questions, answers and puzzles at
www.technical-interview.com

Thursday, April 22, 2010

Compute the sum of all the values in the nodes of a single linked list

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;

}

No comments:

Post a Comment