I am trying to recursively append an element to the end of a Linked List .However, Nothing seems to be added. I use a private helper method so I can use the reference as a parameter. I don't run into any exceptions, however, my test cases show that nothing at all has been added to the list! I have no idea what I'm doing wrong, and have no idea where to start. Your help is very appreciated.
public void addLast(E element) {
addLast(element,first);
}
private void addLast(E element, Node ref) {
if (ref == null) {
ref = new Node(element);
n++;
} else if (ref.next == null) {
ref.next = new Node(element);
n++;
} else {
addLast(element, ref.next);
}
}