Trying to brush up on some concepts. I am trying to find the minimum value present amongst all Nodes in a Linked List implementation. I think for some reason my code is returning all the recursive return values, instead of only the last one. Can somebody check please what looks to be the issue in my findMin method?
public class Node
{
public int data;
public Node next;
public Node(int d)
{
data = d;
next = null;
}
}
public static int findMin(Node head,int min=0)
{
if (min == 0)
min = head.data;
if (head.data < min)
{
min = head.data;
}
else
{
findmin(head.next, min);
}
return min;
}