public void length() {
System.out.println(length(head, 0));
}
public int length(Node he, int count) {
if(he!=null) {
// System.out.println(he.data +" "+count++);
// count++;
// return length(he.next, count);
return length(he.next, count++);
}
return count;
}
In the code above, I have to find the length of linked list. If I run the same code, I am getting the length 0.But, when i use commented code and I am getting the correct length. Why is that happening?