I need to make some methods for a LinkedList that use recursion. I have some that are good but this is one of the ones that is giving me trouble:
public boolean find(T data){
if(head == null)
return false;
else{
if(head.data == data)
return true;
else{
head = head.next;
return find(data);
}
}
}
It's supposed to find an element in the LinkedList but the problem is, the List shouldn't be appended, which obviously mine is with head's position increasing. The prototype is supposed to have 1 parameter, the data one. How can I get it to stop increasing the head position?